ioscocoa-touchuiviewautorelease

When will a autorelease get released


I am looking to to develop an app where there will be "n" number of views created based on the user's interaction. If each of these views are created dynamically with autorelease, when will the view actually be released?

Lets say there are 10 views, all being dynamically created views with autorelease:

  1. View 1 is created and added to a navigation stack, user is shown view 1
  2. User moves to another view "View 2", View 1 is pushed off the stack and View 2 is added. Will View 1 be released here? I would not want it to be released, so should i retain it?
  3. The problem is, i might not know how many views i am creating, so deallocating them manually might be problem, or is there a way?

I am a little confused soul here.

Thanks


Solution

    1. You don't add views to navigation stack, you add view controllers.
    2. When you push view controller 2, the 1st one will not get released, no. Navigation controller will always keep all it's view controllers retained until they are popped off the stack. It will only call -unloadView on non-displayed view controllers to free up some memory, but if you are creating your views inside view controllers' loadView method, everything will get recreated automatically.
    3. You don't dealloc anything manually, you can only release it. Since navigation controller will retain any view controller you add on it's stack, you are free to release it yourself.

    From the way you ask your questions, I've noticed you are missing some very basic knowledge about iOS SDK, MVC and OOP in general. I would honestly suggest you try creating a much simpler app than that chat app of yours first to learn some basics.