• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: String memory leak
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: String memory leak


  • Subject: Re: String memory leak
  • From: Paul Forgey <email@hidden>
  • Date: Sun, 2 Apr 2006 17:37:01 -0700

This isn't a gotcha, nor is it really correct if you mean the items will be leaked after the array is destroyed.

If you add an object to an NSArray (or most any other container), that item is retained once for being in the container. It gets released if you remove it from the container too. If the container itself is retained or released beyond that it has no impact on the items it owns (nor should it).

Now if you destroy the container with a matching number of releases, then all the items are released just as if they were removed.

There's no need to manually release all items unless you didn't release them after adding them in the first place:

SomeObject *object = [[SomeObject alloc] init];
[array addObject:object];
[object release]; // container now "owns" object we are done with

Which also means you can easily add autoreleased items:
[array addObject:[NSString stringWithFormat:....]];


On Apr 1, 2006, at 5:01 AM, Chris Lewis wrote:

1. Do you ever deallocate the surfaces at all? A gotcha I read about
is that if you release the NSArray, all you do is release the NSArray,
and not the objects inside it. You need to release those first. If
they don't get released, you'll leak the strings as well.

_______________________________________________ Do not post admin requests to the list. They will be ignored. Cocoa-dev mailing list (email@hidden) Help/Unsubscribe/Update your Subscription: This email sent to email@hidden
  • Follow-Ups:
    • Re: String memory leak
      • From: "Chris Lewis" <email@hidden>
References: 
 >String memory leak (From: Bruce Truax <email@hidden>)
 >Re: String memory leak (From: "Chris Lewis" <email@hidden>)

  • Prev by Date: Making an iTunes style bar
  • Next by Date: Re: String memory leak
  • Previous by thread: Re: String memory leak
  • Next by thread: Re: String memory leak
  • Index(es):
    • Date
    • Thread