(void)observeValueForKeyPath:(NSString*)keyPath ofObject:(id)object change:(NSDictionary*)change context:(void*)context There was a lot of code involved, which made it more difficult to MYChild I’m only giving the bare essentials here. Moreover, I need to kill some time before football season kicks off.īelow is a simplified version of a crasher I once discovered and fixed. Thus, I believe that writing a series of posts exploring the subtleties of Cocoa memory management is a worthy endeavor. In practice, however, they’re not even expert-proof, as we see when the experts’ apps unexpectedly quit. Each of the aforementioned method calls must be balanced at some point by a call to -release, if it’s safe for the object to deallocate immediately, or -autorelease, if you need the object to stick around until the end of the event loop. A reference obtained in any other way is guaranteed to be valid only during the current event loop, so you’ll need to call -retain if the reference should remain valid for longer (e.g., if you want to store it in an instance variable). ![]() If you obtain a reference to an object by calling +alloc, +allocWithZone:, +new, or -copy, then the reference should remain valid indefinitely. Just set GCC_ENABLE_OBJC_GC = required and wait for the money to roll in, right? For those who don’t enjoy the smell of Objective-C garbage collection, we have the tried-and-true manual rules. ![]() Supposedly, the rules of Cocoa memory management are simple. Not to mention your optics and your closet. If I were to offer one bit of advice to young programmers, I would say always … uh … never … forget to check your references.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |