I have an application written in Cocoa with ARC which allows the user to create and open new windows. (It's like a document model, but I'm not using nsdocument.)
Each new window requires a large amount of memory, which I would like to get back if the user closes the window.
I understand that [window close]
simply hides the window, but I'm also using [[self window] setReleasedWhenClosed:YES]
, but both the NSwindowcontroller
and its window are still in existence after the close.
The objects in my window's xib file contain a number of large c arrays allocated with malloc, so I've also tried freeing them by sending a call to the notification center inside the windowcontroller's windowWillClose:
method, where the notification calls a method inside the relevant objects to free the C arrays before the window closes. Again, this is to no effect- even though the method attempting to free the arrays is called and the arrays are apparently freed, according to Activity Monitor, no memory is ever released. I've also tried freeing the arrays in -(void) dealloc
, but this doesn't appear to ever be called upon a close.
So, how can I best get the memory back when a window is closed?
Edit: According to a comment on this stackoverflow page by Benoit,
"Release when closed, however, is ignored for windows owned by window controllers."
Is that true? If so, how can I get around that in ARC?