开发者

NSobject's release query?

hi i am a newbie developer, building my first app, i have a impportant question -

lets say we are using TableviewController and have used few NSMut开发者_StackOverflow中文版ableArray objects and have a ManagedObjectContext object to fetch the data to display. now if i move to another view and release all the object i have instantiated using [[nsObject alloc] init] in the present view, it all works fine in we are in the next view but as soon as we click back button we dont have the NSObjects thatwe used to create the previous view so the app Crashes. what i did was left the objects without releasing. is it good or bad?


You usually shouldn't be releasing just for pushing another view controller on the stack. You should release when you don't need the objects anymore. In this case, you need the objects still because you are coming back to it. I would release your objects in your dealloc method, called whenever this view controller is done with them and is getting released itself.

If you are determined to release them as you push the app, you will need to re-fetch them when you come back before trying to do anything, this is much more complicated when compared to just retaining them.


Another Idea is to save the data in pList but it depends what you are saving. when you change the view, save it and when you come back again to the same view, retrive it from the plist

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜