NSDocument leak with top-of-NIB object controllers (10.6 ARC)
NSDocument leak with top-of-NIB object controllers (10.6 ARC)
- Subject: NSDocument leak with top-of-NIB object controllers (10.6 ARC)
- From: Fritz Anderson <email@hidden>
- Date: Thu, 22 Dec 2011 13:29:40 -0600
Xcode 4.2, 10.7 SDK, target 10.6, ARC ("weak" pointers must be unsafe_unretained).
I had the following problem, which I solved, but I don't trust the solution:
When I used heapshotting to see what happened when I repeatedly opened and closed my document, I was accumulating a lot of memory as the document and its data were never released. All the retains and releases with my code in the stack trace were balanced.
The document's NIB (no, I don't put the document in the NIB, and I'm using the window controller that comes with the document) contains an NSObjectController and an NSArrayController at the top level. Per "Patterns for Managing Outlets Become Consistent Across Platforms" in the "Transitioning to ARC Release Notes," the IBOutlet properties for those controllers were declared strong.
But my residual retain count was 2, and a couple of the retains were in the NIB-loading mechanism, so I tried setting the outlets for those controllers to nil at -windowWillClose: time.
This cured the leak. So did making the outlets unsafe_unretained (though that leaked slightly more).
I don't see that there should be _harm_ in this, but I worry, because it goes against the documentation (at least the documentation I could find). I've developed a theory, and I'd like to know if it's superstitious:
• For projects targeting 10.7 or later, and using ARC, the references should be strong, as documented. (But how does the OS know whether that class in particular is using ARC? Products can be mixed.)
• If the target is 10.6, even if running on 10.7, regardless of whether ARC is used, the references should be unsafe_unretained/assign, to match the behavior of the target operating system.
Do I have this right?
— F
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden