Re: dealloc and Instances created from IB
Re: dealloc and Instances created from IB
- Subject: Re: dealloc and Instances created from IB
- From: Andy Lee <email@hidden>
- Date: Wed, 13 Mar 2002 15:40:25 -0500
At 2:43 PM -0500 3/13/02, Matt Thomas wrote:
>
Sorry if this is a newbie question:
>
>
I created a class in Interface Builder, instantiated it, made the proper connections, and then created the files. I then edited the class and added init and dealloc methods in the class. I was then debugging the class and it looks like dealloc was not being called.
>
>
So my questions is, if i have an instance of a class created in Interface Builder, will it's dealloc method ever be called? Is there a method I can use to make sure clean up goes okay when I release an object?
The way to make sure -dealloc gets called at the right time, and only at the right time, is to properly balance your retains and releases, and to understand when -retain, -release, and -autorelease get called implicitly by Cocoa objects.
An object created in IB is like any other -- it will be dealloc'ed when its retain count goes to zero. There's nothing special about objects in IB in terms of memory management.
If you have controls in the nib file pointing to your custom object (for example, using it as a target or a delegate), that increases its retain count. That would explain why a mere [myObject release] doesn't cause -dealloc to be called -- because it shouldn't, because your program isn't done with the object yet, because you still have a button using it as a target (or a text field using it as a delegate, or whatever).
--Andy
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.