Re: Question Re Memory Management in Apps
Re: Question Re Memory Management in Apps
- Subject: Re: Question Re Memory Management in Apps
- From: "Hank Heijink (Mailinglists)" <email@hidden>
- Date: Tue, 9 Mar 2010 14:12:56 -0500
On Mar 8, 2010, at 10:44 PM, Philippe Sismondi wrote:
> In other words, the MadeObj instance for AppController's instance variable is created and then immediately dealloc'd. I take this to mean that the autorelease pool it was in was released/drained. If I change the AppController init method to retain instanceMadeObj, the dealloc does not happen.
Correct.
> I don't understand this. When is the autorelease pool created/released? I would guess that the AppController instance is created outside the main event loop. If the answer is in the Memory Management Programming Guide, it is not obvious to me. I did not expect that I should autorelease the instance variable in this case.
Read the Cocoa Fundamentals Guide:
http://developer.apple.com/mac/library/documentation/Cocoa/Conceptual/CocoaFundamentals/CocoaObjects/CocoaObjects.html#//apple_ref/doc/uid/TP40002974-CH4-SW39
From the section "How Memory Management Works":
"If you are developing an application you may not need to set up an autorelease pool; the Application Kit automatically sets up an autorelease pool scoped to the application’s event cycle."
This explains the behavior you're seeing: every time your application goes through its event cycle, the main autorelease pool is drained.
Hope this helps,
Hank
_______________________________________________
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