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:

  • View 1 is created and added to a navigation stack, user is shown view 1
  • 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?
  • 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


  • You don't add views to navigation stack, you add view controllers.
  • 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.
  • 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.


    It will help if you post key segments of your code so we can see what you are doing. In short, if a view controller is in the navigation stack, it will be retained by the navigation controller. If it is popped off but you want to keep it, you'll need to retain it from another controller, probably the one that presents it.

    链接地址: http://www.djcxy.com/p/53278.html

    上一篇: C返回自动发行副本

    下一篇: autorelease何时发布