profile for monkeydom at Stack Overflow, Q&A for professional and enthusiast programmers


coding bits I use, come across, like, hate, the whole shebang.

twitter | github | mastodon     rant-dom     rss | archive


Retain, Release, Autorelease, etc.

Something I tend to do, which saved my but quite some time. Interestingly enough this is somewhat discouraged in iPhone OS due to the overhead of autoreleases and the relatively small power of the platform.

Instead of:

SomeClass *myInstance = [[SomeClass alloc] init];
// do something with myInstance
[myInstance release]; // release it again

I do:

SomeClass *myInstance = [[[SomeClass alloc] init] autorelease];
// do something with myInstance

Straight away. That really helps me avoid complexity and stupid releasing bugs caused by the // do something with myInstance block having an early return, branches, or other issues.