On Oct 15, 2013, at 12:50 PM, Steve Mills <smi...@makemusic.com> wrote:
> Instruments shows that we're leaking NSArrays created when itemArray returns. > I assume whoever wrote these methods was assuming that itemArray would simply > return the internal NSArray and not make a copy. You don’t need to release the return value of -itemArray. It’s a public method, and by the standard Cocoa convention it returns an autoreleased result (since its name doesn’t start with ‘alloc’, ‘new’ or ‘copy’.) > NSArray* items = [self itemArray]; > for(NSMenuItem* item in items) > blah; > [items release]; That’s going to crash by over-releasing ‘items’. _Unless_ something in the “blah” code is accidentally retaining the array. But in that case you need to fix the “blah” code itself, not tack on an extra -release at the end of the loop as a band-aid for the leaking. Have you run the Clang static analyzer on your code? It’s very good at finding these sorts of problems. —Jens _______________________________________________ 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: https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com