Skip to content

Commit b2c913e

Browse files
committed
• Added method -[SSYOperationQueue tearDown].
• Added comment un-recommending SSYMOCManager.
1 parent cac38e4 commit b2c913e

4 files changed

+34
-6
lines changed

SSYMOCManager.h

+4
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@
1414
which the owner is desired turns out to not be one of this class's creations.
1515
This class itself is instantiated as an app-wide
1616
singleton and no public instance methods are available.
17+
18+
UPDATE 2018-12-28. I do not recommend using this class, which I wrote I
19+
think in 2009, any more, because it is easy to cause retain cycles which are
20+
tricky to unravel.
1721
1822
When using this class, [NSApp delegate] must conform to protocol
1923
SSYAppSupporter.

SSYManagedObject.h

+8-2
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,8 @@ extern NSString* const constKeyNewValue ;
121121
and definition of "owner". If the owner must be of a specific type or
122122
conform to a certain formal protocol, you can re-declare and override this
123123
method in subclasses. The implementation simply returns super's owner.
124+
125+
UPDATE 2018-12-28. This method is not recommended. Use -allocOwner instead.
124126
@result The owner of the receiver
125127
*/
126128
- (id)owner;
@@ -130,11 +132,15 @@ extern NSString* const constKeyNewValue ;
130132
that is not in the autorelease pool – the caller "owns" it
131133
132134
@details This method is recommended instead of -owner whenever the owner is
133-
a transient object which may not be deallocced due to retain cycles with the
134-
receiver. Keep in mind that Core Data can be quite anal-retentive:
135+
a transient object which may not be deallocced for a long time due to the
136+
unpredictable release of the autoreleased owner. This may be exacerbated by
137+
the anal-retentive nature of Core Data, some of which is explained in here.
135138
136139
https://developer.apple.com/library/archive/documentation/Cocoa/Conceptual/CoreData/MO_Lifecycle.html
137140
141+
Note that the problem being solved here is an artifact of autorelease pools.
142+
The problem would be moot if we were using Automatic Reference Counting (ARC).
143+
138144
The reason for the prefix 'alloc' is that, of the four prefixes which
139145
tell the clang objective-c static analyzer that this method returns an object
140146
which the caller "owns", as explained here

SSYOperationQueue.h

+10
Original file line numberDiff line numberDiff line change
@@ -284,4 +284,14 @@ extern NSString* const SSYOperationQueueDidEndWorkNotification ;
284284

285285
- (void)doDone:(NSDictionary*)doneInfo ;
286286

287+
/*!
288+
@brief Removes an internal observer which observes the owner of the first
289+
operation in the receiver's queue.
290+
291+
@details To prevent crashes, you should send this prior to the owner of the
292+
receiver's operations being deallocced.
293+
*/
294+
295+
- (void)tearDown;
296+
287297
@end

SSYOperationQueue.m

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

2222
@property (retain) id noAppNapActivity ;
23+
@property (assign) BOOL didTearDown;
2324

2425
@end
2526

@@ -128,11 +129,18 @@ - (id)init {
128129
return self ;
129130
}
130131

132+
- (void)tearDown {
133+
if (!self.didTearDown) {
134+
[self removeObserver:self
135+
forKeyPath:@"operations"];
136+
self.didTearDown = YES;
137+
}
138+
}
139+
131140
- (void)dealloc {
132-
// Probably this is not necessary but I'm paranoid about KVO.
133-
[self removeObserver:self
134-
forKeyPath:@"operations"] ;
135-
141+
/* This should have already been done, but in case not… */
142+
[self tearDown];
143+
136144
[m_error release] ;
137145
[m_scriptCommand release] ;
138146
[m_scriptResult release] ;

0 commit comments

Comments
 (0)