Open main menu

lensowiki β

IPhone development tips

Revision as of 04:33, 28 December 2009 by Lensovet (talk | contribs) (Created page with '*Distinction between calling [self.property release] and self.property = nil :The latter will allow you to assign the variable later and should generally be used when you want to…')
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
  • Distinction between calling [self.property release] and self.property = nil
The latter will allow you to assign the variable later and should generally be used when you want to "clear" a variable for memory saving purposes but will have a need to assign a value to it again sometime in the future. release will completely invalidate the object and attempting to call anything on it afterwards will result in a EXC_BAD_ACCESS error every time. What does this mean in the grand scheme of things? You will most likely use release in only one place in your code – the object's dealloc method.
  • Watching out for deallocation and unloading of views
Keep in mind that if a bunch of view controllers nested one above the other, there's a bunch of unloading and deallocating happening when these views disappear (hopefully, as you should be keeping your memory usage to a minimum). In one of my view controllers, I was overfreeing controller properties because I attempted to free them inside both viewDidUnload: and dealloc methods. Just remember that a view should only be getting dealloc'ed after it's been unloaded, so you only need to free most things in viewDidUnload:.