• 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: Andy Lee <email@hidden>
  • Date: Sat, 1 Apr 2006 10:07:38 -0500

On Apr 1, 2006, at 7:30 AM, Bruce Truax wrote:
The command line tool "leaks" is telling me that I have an 80 byte leak of
type NSCFString everytime I execute the following method:


- (void)GLASS:(NSString *)parameterString
{
    [aSurface setGlass:[NSString stringWithFormat:
        @"GLASS %@", parameterString]];
    [aSurface setSurfaceNumber:surfaceNumber];
    surfaceNumber++;
    [surfaceArray    addObject:aSurface];
    aSurface = [[ACSurface alloc]init];

}

Every time you call this method you're setting aSurface to a new instance of ACSurface without releasing the previous value of aSurface. So you are leaking instances of ACSurface, each of which contains an NSCFString.


You could create a -setSurface: method, using one of the proper patterns for a setter method, and call that instead of using assignment to set aSurface. Or, if this is the only place you set aSurface, you could use that pattern right in this method.

Should I be using the following instead?

  [aSurface setGlass:[[NSString alloc] initWithFormat:
        @"GLASS %@", parameterString]];

No, this would make the problem worse, because the string you would be passing to -setGlass: would be over-retained.


--Andy

_______________________________________________
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: Bruce Truax <email@hidden>
References: 
 >String memory leak (From: Bruce Truax <email@hidden>)

  • Prev by Date: Re: memory problem, advice needed
  • 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