Quote:
Originally Posted by .mb
Ahh, that makes sense. One more question, if I could. I'm trying to destroy objects dynamically, but I'm drawing a blank on how to remove it from memory... Trying to use [object dealloc] just freezes the application, and removing it from the array does the same.
|
Objects get destroyed when their "retain count" hits zero. Usually, that means you intit the object (for a count of one) and it gets destroyed when you release it. You never call dealloc yourself.
The confusion comes in when you *don't* init the objects - many classes have "convenience methods" that give you "autorelease" objects, that will release themselves at the end of the current event. If you release an object you did not init, you usually get a crash.
Properties and arrays/dictionaries also retain objects when you add them, and release them once when you remove them.
This is the page that put it all together for me:
Very simple rules for memory management in Cocoa
PS- views also retain their subviews. So you'll have to call [deadView removeFromSuperview] too, if it's a view.