Iam having a very basic doubt in memory management. If suppose iam allocating memory for an object in viewWillAppear method. Should i release the object in viewWillDisappear method or in the release all the objects in开发者_JAVA技巧 the de
It's dependent when you want to release the object. You don't have to release on viewWillDisappear. But, you can, just think about when you need it and when you don't. Technically, either one is fine. Depending on the situation though I would think: if you need the object for multiple views don't dealloc in viewWillDisappear, if you need it only for that view and you don't need it again, dealloc in viewWillDisappear.
Here's a very easy to learn tutorial on objective-c memory management.
http://cocoadevcentral.com/d/learn_objectivec/
You'll learn a lot about retaining and releasing variables. In general variables are defined according to scope (i.e where they will be used) For example, you may want to initialize a variable that's used throughout a class in viewDidLoad and release it in dealloc. It all depends on where you need to store data and for how long.
精彩评论