Radix
Radix

Reputation: 3657

Does system release my objects when the application is terminated?

i always wonder sometimes that when i run my app an app pool is created and my app gets loaded inside the app pool and when i hit the home button my app is terminated i.e. the pool in which my app was residing will be terminated so in this case what will happen to those objects if i do not release such objects i think they will be terminated too but this methodology is not recommended by apple god knows for what reason. Can any gentleman provide me a solid answer for this question because it has really bugged me a lot these days..

Thanks & Regards

Upvotes: 1

Views: 250

Answers (4)

ingconti
ingconti

Reputation: 11646

Apple docs clearly stated (the same in OSX) that on exiting o.s. simply reclaim ram. And in latest OSes also "applicationWillTerminate" behavior is affected similarly. The logic is that not useful to release part of a dying app.

(see also Are there drawbacks to Snow Leopard's new "sudden termination" mechanism? for OSX)

A different problem is if You need special behavior when you are quitting: - saving prefs - send a "goodbye" to a server..and so on.

Both cases are in my opinion wrong: - you must save prefs every time as apple suggests for user setting, - server should have a time out.

the same logic will cover the case app crashes.

Upvotes: 0

zoul
zoul

Reputation: 104065

Whenever your application is terminated the memory it had allocated is returned to the system. Autorelease pools don't play any role in this case, if that's what you mean by "application pool". The objects that are still in memory at that moment will not be deallocated (in the sense that system would call dealloc for you), the corresponding memory is simply marked as free.

Upvotes: 7

JeremyP
JeremyP

Reputation: 86651

Each application has its own virtual memory address space in much the same way as you would expect for any "real" computer. When an app is terminated, its entire virtual memory disappears and the physical memory is reclaimed by the operating system.

So technically, when your app terminates there is no need to release any of the objects you currently have allocated but if you're managing your memory properly, you'll find it is actually hard to fail to release your objects.

AFAIK the term "application pool" has no meaning inside iOS.

Upvotes: 1

Antwan van Houdt
Antwan van Houdt

Reputation: 6991

Autoreleasepools are created and destroyed many times during the runtime of your application ( at the beginnig and the end of a runloop in any case ).

When your application is terminated by the home button all the memory your application was using will be released and useable by any other app the same way you would expect that to work on your home computer.

Upvotes: 0

Related Questions