Clearly, there is a lot more going on in the code in this question than in typical Cocoa code.

That said, if you want to avoid bugs, it would seem that the following is good advice:

* Always use autorelease.
* Use an Auto Release Pool if necessary (in loops, or with large memory allocations), remembering that ARPs are fast <http://www.mikeash.com/?page=pyblog/autorelease-is-fast.html>.

Now, as has been stated, you can make an efficiency case to use release where you really know that the item will be retained past the end of this event loop. To me, that is just a bug waiting to happen when you make some other change to the code, for a benefit that is almost certainly irrelevant and which should be ignored until such time as you have profiled your code and found a hot spot.

I read again about the Clang static code analyzer today, and how it has found thousands of bugs in real world applications. I recently ran it on my code and it found no bugs, as did a friend of mine who has a similar coding style. I don't think it's a coincidence that a coding style designed to be a bit conservative and to look for ways to write bug free code produces code that has no bugs that can be detected by Clang. And things like this advice to always used autorelease (which I freely admit I only heard recently) strike home because they make it easier to write code without bugs.

Enjoy,
   Peter.

--
              Keyboard Maestro 3 Now Available!
                Now With Status Menu triggers!

Keyboard Maestro <http://www.keyboardmaestro.com/> Macros for your Mac
<http://www.stairways.com/>           <http://download.stairways.com/>
_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]

Reply via email to