Skip to content

Commit 72a837b

Browse files
committed
• Removed the property from SSYOperation and SSYOperationQueue. Even though this was an 'assign' property, and therefore not causing memory retain cycles, it created a lot of noise in Xcode's new memory graph debugger and, in general, it was never a very good programming practice since there is almost always a better way to reference an 'owner'.
• Removed -[SSYOperationQueue tearDown] because its only purpose was to release the now-gone 'owner'. • In -[SSYOperationQueue queueGroup:::::::::], removed a local variable 'operations' which appears to have been not used for a long time.
1 parent 4fc989b commit 72a837b

4 files changed

+24
-94
lines changed

SSYOperation.h

+1-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
#import <Cocoa/Cocoa.h>
2-
#import "SSYOwnee.h"
32

43
@class SSYOperationQueue ;
54

@@ -26,11 +25,10 @@
2625
if these two values are equal as judged by +[SSYOperationQueue
2726
operationGroupsDifferInfo:otherInfo:],
2827
*/
29-
@interface SSYOperation : NSOperation <SSYOwnee> {
28+
@interface SSYOperation : NSOperation {
3029
NSMutableDictionary* m_info ;
3130
SEL m_selector ;
3231
id m_target ;
33-
id m_owner ; // weak
3432
SSYOperationQueue* m_operationQueue ; // weak
3533
NSInvocation* m_cancellor ;
3634
BOOL m_skipIfError ;
@@ -76,7 +74,6 @@
7674
- (id)initWithInfo:(NSMutableDictionary*)info
7775
target:(id)target
7876
selector:(SEL)selector
79-
owner:(id)owner
8077
operationQueue:(SSYOperationQueue*)operationQueue
8178
skipIfError:(BOOL)abortIfError ;
8279

SSYOperation.m

+5-16
Original file line numberDiff line numberDiff line change
@@ -60,14 +60,6 @@ @implementation SSYOperation
6060
@synthesize skipIfError = m_skipIfError ;
6161
@synthesize lock = m_lock ;
6262

63-
- (id)owner {
64-
return m_owner ;
65-
}
66-
67-
- (void)setOwner:(id)owner {
68-
m_owner = owner ;
69-
}
70-
7163
- (void)cancel {
7264
[[self cancellor] invoke] ;
7365
[self setInfo:nil];
@@ -87,7 +79,6 @@ - (void)dealloc {
8779
- (id)initWithInfo:(NSMutableDictionary*)info
8880
target:(id)target
8981
selector:(SEL)selector
90-
owner:(id)owner
9182
operationQueue:(SSYOperationQueue*)operationQueue
9283
skipIfError:(BOOL)skipIfError {
9384
self = [super init] ;
@@ -96,7 +87,6 @@ - (id)initWithInfo:(NSMutableDictionary*)info
9687
[self setInfo:info] ;
9788
[self setSelector:selector] ;
9889
[self setTarget:target] ;
99-
[self setOwner:owner] ;
10090
[self setOperationQueue:operationQueue] ;
10191
[self setSkipIfError:skipIfError] ;
10292
}
@@ -238,14 +228,13 @@ - (void)main {
238228
NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init] ;
239229
#if LOGGING_SSYOPERATIONLINKER_OPERATIONS
240230
NSString* msg = [NSString stringWithFormat:
241-
@"RunOp: %p grp=%@ prevErr=%ld nQ=%ld sel=%@ isCnc=%hhd owr=%p",
231+
@"RunOp: %p grp=%@ prevErr=%ld nQ=%ld sel=%@ isCnc=%hhd",
242232
self,
243233
[[self info] objectForKey:constKeySSYOperationGroup],
244234
(long)[[self error] code],
245235
(long)[[[self operationQueue] operations] count], // nQ = number in queue
246236
NSStringFromSelector([self selector]),
247-
[self isCancelled],
248-
[self owner]];
237+
[self isCancelled]];
249238
[[BkmxBasis sharedBasis] logMessage:msg];
250239
#endif
251240

@@ -277,19 +266,19 @@ - (void)main {
277266
// Chain operations have been aborted.
278267
// This method becomes a no-op.
279268
#if LOGGING_SSYOPERATIONLINKER_OPERATIONS
280-
[[BkmxBasis sharedBasis] logMessage:@"RunOp: Skipping %@ cuz error owr=%p", NSStringFromSelector([self selector]), [self owner]];
269+
[[BkmxBasis sharedBasis] logMessage:@"RunOp: Skipping %@ cuz error op=%p", NSStringFromSelector([self selector]), self];
281270
#endif
282271
}
283272
}
284273
else {
285274
#if LOGGING_SSYOPERATIONLINKER_OPERATIONS
286-
[[BkmxBasis sharedBasis] logMessage:@"RunOp: Skipping %@ cuz skip group %@ owr=%p", NSStringFromSelector([self selector]), [[self info] objectForKey:constKeySSYOperationGroup], [self owner]];
275+
[[BkmxBasis sharedBasis] logMessage:@"RunOp: Skipping %@ cuz skip group %@ op=%p", NSStringFromSelector([self selector]), [[self info] objectForKey:constKeySSYOperationGroup], self];
287276
#endif
288277
}
289278
}
290279
else {
291280
#if LOGGING_SSYOPERATIONLINKER_OPERATIONS
292-
[[BkmxBasis sharedBasis] logMessage:@"RunOp: Skipping %@ cuz cancelled owr=%p", NSStringFromSelector([self selector]), [self owner]];
281+
[[BkmxBasis sharedBasis] logMessage:@"RunOp: Skipping %@ cuz cancelled op=%p", NSStringFromSelector([self selector]), self];
293282
#endif
294283
}
295284

SSYOperationQueue.h

+4-22
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,7 @@ extern NSString* const constKeySSYOperationQueueDoneSelectorName ;
1212
@brief Name of a notification, enqueued on the main thread, when the
1313
number of tasks in the receiver's queue increases from 0.
1414
15-
@details The notification object is the -owner of the first
16-
operation in the queue, which may be nil if it was
17-
so set, or if this operation does not respond to selector
18-
-owner (as could happen if superclass methods were used to
19-
add the operation), then the notification object is the
20-
receiver.
15+
@details The notification object is the receiver.
2116
2217
There is no userInfo dictionary.
2318
@@ -40,12 +35,7 @@ extern NSString* const SSYOperationQueueDidBeginWorkNotification ;
4035
@brief Name of a notification, enqueued on the main thread, when the
4136
number of tasks in the receiver's queue decreases to 0.
4237
43-
@details The notification object is the -owner of the last
44-
operation which was in the queue, which may be nil if it was
45-
so set. But if this operation does not respond to selector
46-
-owner (as could happen if superclass methods were used to
47-
add the operation), then the notification object is the
48-
sending SSYOperationQueue object.
38+
@details The notification object is the receiver.
4939
5040
There is no userInfo dictionary.
5141
@@ -56,7 +46,7 @@ extern NSString* const SSYOperationQueueDidEndWorkNotification ;
5646
@interface SSYOperationQueue : NSOperationQueue {
5747
// Note that we do not enter the doneTarget, doneSelector and
5848
// doneThread as instance variables, because they may be different
59-
// for each group of operations entered with queueGroup:::::::::.
49+
// for each group of operations entered with queueGroup::::::::.
6050
// But the following instance variables are common to all groups...
6151
NSError* m_error ;
6252
NSScriptCommand* m_scriptCommand ;
@@ -218,10 +208,6 @@ extern NSString* const SSYOperationQueueDidEndWorkNotification ;
218208
immediately, after queueing the operations. This method simply sends
219209
-waitUntilAllOperationsAreFinished to your <i>queue</i>. Again, if you
220210
pass NO, remember to retain the arguments <i>queue</i> and <i>info</i>.
221-
@param owner An object which will be passed as the 'owner' to each of
222-
the SSYOperations which are manufactured by the receiver during execution
223-
of this method, including the `done` operation which encasulates the
224-
doneThread, doneTarget and doneSelector.
225211
@param doneThread The thread in which a message will be sent after
226212
the last operation in selectorNames is completed. If doneThread is nil,
227213
the default thread assumed will be the currentThread (the thread on which
@@ -252,7 +238,6 @@ extern NSString* const SSYOperationQueueDidEndWorkNotification ;
252238
selectorNames:(NSArray*)selectorNames
253239
info:(NSMutableDictionary*)info
254240
block:(BOOL)block
255-
owner:(id)owner
256241
doneThread:(NSThread*)doneThread
257242
doneTarget:(id)doneTarget
258243
doneSelector:(SEL)doneSelector
@@ -285,13 +270,10 @@ extern NSString* const SSYOperationQueueDidEndWorkNotification ;
285270
- (void)doDone:(NSDictionary*)doneInfo ;
286271

287272
/*!
288-
@brief Removes an internal observer which observes the owner of the first
289-
operation in the receiver's queue.
273+
@brief Removes an internal observer which observes the receiver itself.
290274
291275
@details To prevent crashes, you should send this prior to the owner of the
292276
receiver's operations being deallocced.
293277
*/
294278

295-
- (void)tearDown;
296-
297279
@end

SSYOperationQueue.m

+14-52
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
@interface SSYOperationQueue ()
2121

2222
@property (retain) id noAppNapActivity ;
23-
@property (assign) BOOL didTearDown;
2423

2524
@end
2625

@@ -129,17 +128,9 @@ - (id)init {
129128
return self ;
130129
}
131130

132-
- (void)tearDown {
133-
if (!self.didTearDown) {
134-
[self removeObserver:self
135-
forKeyPath:@"operations"];
136-
self.didTearDown = YES;
137-
}
138-
}
139-
140131
- (void)dealloc {
141-
/* This should have already been done, but in case not… */
142-
[self tearDown];
132+
[self removeObserver:self
133+
forKeyPath:@"operations"];
143134

144135
[m_error release] ;
145136
[m_scriptCommand release] ;
@@ -177,19 +168,19 @@ + (BOOL)operationGroupsSameInfo:(NSDictionary*)info
177168
return NO ;
178169
}
179170

180-
- (void)postQueueDidBeginWorkForObject:(id)object {
171+
- (void)postQueueDidBeginWork {
181172
NSNotification* notification = [NSNotification notificationWithName:SSYOperationQueueDidBeginWorkNotification
182-
object:object] ;
173+
object:self] ;
183174
[[NSNotificationQueue defaultQueue] enqueueNotification:notification
184175
postingStyle:NSPostNow
185176
coalesceMask:(NSNotificationCoalescingOnName|NSNotificationCoalescingOnSender)
186177
forModes:nil] ;
187178
// See header doc regarding notifications for posting style explanation
188179
}
189180

190-
- (void)postQueueDidEndWorkForObject:(id)object {
181+
- (void)postQueueDidEndWork {
191182
NSNotification* notification = [NSNotification notificationWithName:SSYOperationQueueDidEndWorkNotification
192-
object:object] ;
183+
object:self] ;
193184
[[NSNotificationQueue defaultQueue] enqueueNotification:notification
194185
postingStyle:NSPostWhenIdle
195186
coalesceMask:(NSNotificationCoalescingOnName|NSNotificationCoalescingOnSender)
@@ -238,15 +229,6 @@ - (void)observeValueForKeyPath:(NSString*)keyPath
238229
[scriptCommand resumeExecutionWithResult:[self scriptResult]] ;
239230
[self setScriptCommand:nil] ;
240231

241-
NSOperation <SSYOwnee> * operation = [oldOperations objectAtIndex:0] ;
242-
id owner ;
243-
if ([operation respondsToSelector:@selector(owner)]) {
244-
owner = [operation owner] ;
245-
}
246-
else {
247-
owner = self ;
248-
}
249-
250232
#if MAC_OS_X_VERSION_MAX_ALLOWED >= 1090
251233
// Being built with macOS 10.9 or later SDK
252234
id activity = [self noAppNapActivity] ;
@@ -267,8 +249,8 @@ - (void)observeValueForKeyPath:(NSString*)keyPath
267249
// introduction, not in -operations) that KVO notifications
268250
// for -operations can occur on any thread. However, our
269251
// notifications are expected to be sent on the main thread…
270-
[self performSelectorOnMainThread:@selector(postQueueDidEndWorkForObject:)
271-
withObject:owner
252+
[self performSelectorOnMainThread:@selector(postQueueDidEndWork)
253+
withObject:nil
272254
waitUntilDone:NO] ; // as in NO deadlocks :)
273255

274256
[self setSkipOperationsExceptGroups:nil] ;
@@ -279,7 +261,7 @@ - (void)observeValueForKeyPath:(NSString*)keyPath
279261
// array, the above condition *must* mean that the *count*
280262
// has just changed from 0 to some positive number.
281263
// Actually, even though I add operations one at a time in
282-
// queueGroup:::::::::, I see that I get one notification
264+
// queueGroup:::::::, I see that I get one notification
283265
// when the count jumps from 0 to, say, 5. Apparently,
284266
// KVO notifications are coalesced.
285267

@@ -310,21 +292,12 @@ - (void)observeValueForKeyPath:(NSString*)keyPath
310292
}
311293
#endif
312294

313-
NSOperation <SSYOwnee> * operation = [[self operations] objectAtIndex:0] ;
314-
id owner ;
315-
if ([operation respondsToSelector:@selector(owner)]) {
316-
owner = [operation owner] ;
317-
}
318-
else {
319-
owner = self ;
320-
}
321-
322295
// It is stated in the documentation of NSOperationQueue (in the
323296
// introduction, not in -operations) that KVO notifications
324297
// for -operations can occur on any thread. However, our
325298
// notifications are expected to be sent on the main thread…
326-
[self performSelectorOnMainThread:@selector(postQueueDidBeginWorkForObject:)
327-
withObject:owner
299+
[self performSelectorOnMainThread:@selector(postQueueDidBeginWork)
300+
withObject:nil
328301
waitUntilDone:NO] ; // as in NO deadlocks :)
329302
}
330303
}
@@ -333,7 +306,7 @@ - (void)observeValueForKeyPath:(NSString*)keyPath
333306
- (void)doDone:(NSDictionary*)doneInfo {
334307
NSError* error = [self error] ;
335308

336-
// Note that if the doneTarget provided to queueGroup:::::::::
309+
// Note that if the doneTarget provided to queueGroup::::::::
337310
// was nil or the doneSelector was NULL, doneThread will be nil
338311
// and the following statements will return nil.
339312
NSThread* doneThread = [doneInfo objectForKey:constKeySSYOperationQueueDoneThread] ;
@@ -359,7 +332,6 @@ - (void)queueGroup:(NSString*)group
359332
selectorNames:(NSArray*)selectorNames
360333
info:(NSMutableDictionary*)info
361334
block:(BOOL)block
362-
owner:(id)owner
363335
doneThread:(NSThread*)doneThread
364336
doneTarget:(id)doneTarget
365337
doneSelector:(SEL)doneSelector
@@ -403,7 +375,6 @@ - (void)queueGroup:(NSString*)group
403375
&selectorNames,
404376
&originalInfo,
405377
&block,
406-
&owner,
407378
&doneThread,
408379
&doneTarget,
409380
&doneSelector,
@@ -413,24 +384,17 @@ - (void)queueGroup:(NSString*)group
413384
[info setObject:group
414385
forKey:constKeySSYOperationGroup] ;
415386

416-
// Create an array of operations from the array of selector names
417-
NSMutableArray* operations = [[NSMutableArray alloc] init] ;
418387
for (NSString* selectorName in selectorNames) {
419388
SEL selector = NSSelectorFromString(selectorName) ;
420389
SSYOperation* op = [[SSYOperation alloc] initWithInfo:info
421390
target:nil
422391
selector:selector
423-
owner:owner
424392
operationQueue:self
425393
skipIfError:YES] ;
426-
// Note that operation is double-retained. We'll release it in the next loop.
427-
[operations addObject:op] ;
428394
[self addAtEndOperation:op] ;
429395
[op release] ;
430396
}
431-
432-
[operations release] ;
433-
397+
434398
// Create a final operation which will be the 'done' invocation
435399
// and add it to the queue.
436400
NSMutableDictionary* doneInfo = [NSMutableDictionary dictionaryWithObjectsAndKeys:
@@ -447,8 +411,7 @@ - (void)queueGroup:(NSString*)group
447411
forKey:constKeySSYOperationQueueDoneTarget] ;
448412
[doneInfo setObject:NSStringFromSelector(doneSelector)
449413
forKey:constKeySSYOperationQueueDoneSelectorName] ;
450-
// Added in BookMacster 1.11, for no purpose other than
451-
// filling out -[SSYOperation description] …
414+
// This is to fill out -[SSYOperation description] …
452415
[doneInfo setObject:group
453416
forKey:constKeySSYOperationGroup] ;
454417
}
@@ -457,7 +420,6 @@ - (void)queueGroup:(NSString*)group
457420
SSYOperation* op = [[SSYOperation alloc] initWithInfo:doneInfo
458421
target:self
459422
selector:@selector(doDone:)
460-
owner:owner
461423
operationQueue:self
462424
skipIfError:NO] ;
463425
[self addAtEndOperation:op] ;

0 commit comments

Comments
 (0)