Vincent Gable’s Blog

May 26, 2010

drain an NSAutoReleasePool Don’t release it

To clean up an NSAutoreleasePool, do [pool drain]; not [pool release];

In a garbage-collected environment, sending any object a release message is hardcoded by the runtime to do nothing (very quickly). So [pool release] won’t do anything. But [pool drain] will signal the garbage collector to cleanup, and works correctly (just like release) in a non-garbage-collected environment.

Why This Still Matters on an iPhone

The iPhone doesn’t have garbage collection today. That doesn’t mean it never will. RIM and Android both support some kind of garbage collection. I’m too grizzled an Apple developer to not future proof my code, because I’ve been effected by Apple making some major runtime changes (eg. switching between PowerPC, x86, x86_64, and ARM processors). Section 3.3.1 of the iPhone SDK agreement means Apple’s runtime is the only game in town. It pays to be sure your code always plays nicely with it.

Using drain also helps your code will play nice with Mac OS X. That gives you more options to re-use and monazite it. If you decide to go the open-route, it means more people will be able to use your code.

2 Comments »

  1. Interesting read, I re-designed my site and then the search rankings took an enormous slide
    p.s Never take guidance from people on the Warrior
    Forums :)

    Comment by Damon — April 2, 2015 @ 11:44 pm

  2. The SEO business gets a bad rap from the amount of cowboys and outsourced companies currently set up
    Added to StumbleUpon, they would find this interesting

    Comment by Merle — May 18, 2015 @ 1:00 pm

RSS feed for comments on this post.

Leave a comment

Powered by WordPress