Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

Dealloc never called

Hi,

I have some basic question, i know this thing was discussed a lot of times but some how i just can't find my answer.

My application had a starting point of a Navigation-Based template.
I have a root view controller and two other views (which are also held as class members of the root controller).

My problem is that it seems that the "dealloc" methods (of the root controller or the two other controllers) , where i release retained objects for the controllers, never gets called if i quit the application. i try to set breakpoints in the dealloc methods and none of them is called.

when i work with the memory leak tool no leaks are found.

please,
any ideas ?

thanks.

imac, Mac OS X (10.5.7)

Posted on Nov 2, 2009 4:18 AM

Reply
Question marked as Best reply

Posted on Nov 2, 2009 7:11 AM

Don't worry about that. The SDK does not invoke the dealloc methods when quitting the application (since that is usually a waste of hardware resources). If you need to perform clean up work (closing a database or some such), then use the applicationWillTerminate delegate method.
15 replies

Nov 2, 2009 3:40 PM in response to nkobik

In addition to what sptrakesh said, if you are using XCode 3.1.3 (and maybe 3.1.4) or earlier, get a copy of clang which is freely available on the net, as are installation instructions.

If you are running the very latest XCode, then clang is built in. If it doesn't find any leaks, you are probably OK. It's not perfect, but it checks all the normal things where people end up creating leaks.

Nov 3, 2009 2:55 AM in response to nkobik

Thank you very much for the answers.
i will check this clang tool.
thanks again.

my current situation is that using the Leaks tool, there no leaks indication.
Through Object allocation tool i can see that in the heaviest parts of my application there are about 8M of allocated memory. it's not increasing endlessly.
But still, i experience crashes (sometimes due to low memory warnings).
is there a defined limit of memory usage in which a warning is issued if go beyond it ?

another question - when using the Leaks/Allocation tool with my simulator, everything works great. no leaks, no crashes. when i work with the tool with the Iphone device connected, everything turns realy realy slow and crashes happen all the time. some GUI parts are also loose colors (seems like memory problem) but the object allocation indicates about ~8 - 10 M of allocated memory.

does anybody else experiences a slow system when connecting the device while working with the object allocation tool ?

thanks a lot.

Nov 3, 2009 4:05 AM in response to nkobik

and another question related -

I'm Using navigation control with a main UIViewcontroller and another two UIViewControllers.
both ViewControllers have the functionality of displaying a photo (from the photo library) in a UIImageView.

my question is -
when the back button is tapped in the navigation bar and the current view controller is popped, MUST it be also deallocated ?
currently, my ViewControllers dealloc method is not being called.
my main view controller retains the additional two controllers and i guess that is one of the reasons for the dealloc not being called.
is it an error by me ?
does a UIViewController MUST be deallocated when the view controller is popped ?

thank a lot.

Nov 3, 2009 8:12 AM in response to nkobik

nkobik wrote:
does a UIViewController MUST be deallocated when the view controller is popped ?

No. If you retain the VC in the setter of an ivar, it will have a retain count of +2 after being retained again by the nav controller's array. When the VC is then popped, it's released by the array, so the count is decremented to +1. Thus it will not be dealloced.
\- Ray

Nov 3, 2009 8:02 AM in response to Tech Guru

"If it ain't broke don't fix it"

but it is broken 😟

i'm still experiencing crashes after about 30 min of work.
it is always when i use the navigation back button to return to my root view controller.
i'm also experiencing the weird "leaks" tool behaviour when a device is connected (not simulator) everything goes realy slow.. UI looses colors.. and crashes occur more rapidly.

Nov 3, 2009 8:08 AM in response to RayNewbie

Hi Ray,
and thank a lot for the answer.

i think i understand that,
but still, is this a bad design ? a bad behaiour by me ?

I'm starting to feel that my crashes are related to the fact that both of my view controllers (not the root) have a UIImageView in which they display a photo chosen from photo lib (selected by the user).
are two (large) photos being displayed on two screens (not being release as i learned here) may cause the crashes ?

is it making any sense ?
again, the object allocation instruments does not show any bad memory behaviour.

Nov 3, 2009 8:32 AM in response to nkobik

nkobik wrote:
are two (large) photos being displayed on two screens (not being release as i learned here) may cause the crashes ?


Not releasing memory is not going to cause a crash. The crash is something else.

is it making any sense ?
again, the object allocation instruments does not show any bad memory behaviour.


I just don't understand the obsession with instruments and leaks with iPhone programmers. In one of my previous corporate lives we wrote very large amounts of C++ code in Solaris. One of the last steps was to run Purify (and PureCoverage) on the code to check for orphan code and memory leaks. But you only did that after the program worked perfectly with no crashes.

Memory management is important, but it is only one aspect and not even the most important one.

Nov 4, 2009 12:36 AM in response to etresoft

Thank you all for the answers.

Well, having two large photos didn't (directly) cause the crash. what caused it was a bug in my code which was trigerred by Low-memory warning.

i still wonder though... does 10M of memory taken by my app at the worst case should present these memory warnings ?

and another very basic question ( a bit naive) - are memory warnings are absolute "BAD" thing or is this a normal behaviour by the OS ?
getting a memory warning means my application is designed (or implemented) badly ?

thanks.

Nov 4, 2009 7:00 PM in response to nkobik

nkobik wrote:
i still wonder though... does 10M of memory taken by my app at the worst case should present these memory warnings ?


It is hard to say. Does your app need 10M of memory? That doesn't sound like much, even on an iPhone, but I know nothing about iPhones.

and another very basic question ( a bit naive) - are memory warnings are absolute "BAD" thing or is this a normal behaviour by the OS ?
getting a memory warning means my application is designed (or implemented) badly ?


I would have to say that memory warnings are an absolute BAD. If you see them in development, your users will certainly see them. That will make you look bad and you don't want that.

Instead of worrying about leaks, look at your memory usage. You may not be leaking, but you may be using too much.

Nov 5, 2009 6:26 AM in response to nkobik

nkobik wrote:


but it is broken 😟

i'm still experiencing crashes after about 30 min of work.
it is always when i use the navigation back button to return to my root view controller.
i'm also experiencing the weird "leaks" tool behaviour when a device is connected (not simulator) everything goes realy slow.. UI looses colors.. and crashes occur more rapidly.


I don't recall you mentioning anything about crashes in your original post. I'm certain the crashes don't have anything to do with Dealloc, though. I have to agree with etresoft that the leaks tool is better used when your project is bug-free and working perfectly, so you're kind of wasting some time there. I'd suggest delving into the crash reports a bit more and then posting a new thread if you need help with that.

Dealloc never called

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.