Reputation: 1977
My App tends to crash alot... :(
I know i've been making mistakes in deallocating the views and objects.. I just wanna knw apart from deallocating the memory in the last, how can i manage memory in between the code...
Also my most of the viewcontrollers uses -(void)ViewDidLoad
to create the views..so shud i use -(void)ViewDidUnload
too before deallocating the memory???
If yes, then plz guide me how to use it??
Also is there any other way to solve memory issues??? :(
Upvotes: 0
Views: 65
Reputation: 1984
Keep in mind that viewDidLoad
can be called multiple times, this is especially true in low memory situations where view's can be automatically unloaded to save memory.
In this case you can either check if your object is nil before allocating it, or deallocate it in a memory warning (in didReceiveMemoryWarning
, if self.view.superview == nil
then things will be automatically released).
You should also get to know the profiling tools at some point, or at least the leaks profiler. In Xcode go to Run -> Run With Performance Tool -> Leaks
. There are some issues with this tool you might hit, but once you come to grips you'll wonder how you lived without it (For instance if your host name has special characters in it you'll need to rename it).
Upvotes: 1
Reputation: 6465
If u have created any object in .h file and allocated it only once then u should deallocate that object in this method:
-(void)dealloc { [myObject release]; [super dealloc]; }
but if u have created any object locally (in .m) file then release it at the place where it is not required any more.
Upvotes: 0