• 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: email@hidden (Peter Robinson)
  • Date: Sat, 1 Apr 2006 16:56:01 +0100

Bruce Truax <email@hidden> 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];
> }

It's not obvious to me why you're apparently leaking an NSCFString each
time, but you're certainly causing an instance of /ACSurface/ to be
leaked (later) after every invocation of -GLASS.  You need to -release
the original aSurface instance just before you trash your reference to
it in the last line of that method.  The array will look after its own
reference to aSurface.

In other words, do this:

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

Peter
 _______________________________________________
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: String memory leak
  • Next by Date: Re: cocoa app using external c++ code
  • Previous by thread: Re: String memory leak
  • Next by thread: Re: String memory leak
  • Index(es):
    • Date
    • Thread