Well well.

This leak only occurs if I have sandboxing enabled. What a surprise!

The save dialog is not releasing the document when it closes if sandboxing is 
turned on. If I repeatedly close the window but cancel the save dialog, the 
retain count goes up by about 9 counts each time.

Sandboxing is simply not ready for prime time, and I feel very frustrated that 
it is now compulsory for the App Store when it is this broken.

--Graham







On 30/05/2012, at 12:05 PM, Graham Cox wrote:

> I've got a large memory leak in my app because my document class is never 
> deallocated once I've added content to it.
> 
> I've been over it with a fine-toothed comb and I'm prepared to say it doesn't 
> look as if I'm doing anything wrong. I overrode -retain and set a breakpoint 
> there, so I could see who is retaining the document. Of course, many, many 
> objects do in the complicated new world of autosaving, versions and blocks.
> 
> Every single retain on NSDocument comes from the internals of Cocoa - my code 
> never retains the document at all.
> 
> The key object that seems never to release my document is the NSSavePanel 
> that is displayed only when I have added content, and I close the window. The 
> save panel is shown, and the retain count shoots right up. If I click 'Don't 
> Save', the window closes as expected but the document is still retained - the 
> retain count does not go back down to the point it was at prior to the dialog 
> showing up, and dealloc is never called.
> 
> Key point: If I disable autosaving for my document class, the document is 
> deallocated as expected.
> 
> What I want to know is, is this behaviour correct? It doesn't seem to be 
> correct but it could be - perhaps Versions is retaining my document after its 
> normal lifetime for its own purposes? Obviously I understand that peeking 
> retain counts is a bad strategy for debugging, but just looking at the 
> general trend here, the document ticks over at about a retain count of 3 or 
> 4. When the save dialog is presented, it can shoot up to 17-20 counts, and on 
> closure this drops back to about 12. With autosave/versions disabled, it goes 
> to zero.
> 
> If Versions is retaining documents for some reason, fair enough, I guess I 
> have to accept it. But it causes awkward bugs because of the clean up I 
> expect to do in -dealloc, like unsubscribing from notifications and so on. 
> I'm also a bit uneasy about having large objects like this which are heavily 
> customised in my app hanging around because Cocoa thinks it knows what to do 
> with them - surely it can't know how a particular class has been subclassed 
> and always do the right thing? The way Versions works seems really quite 
> scary to me.


_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to