Re: String memory leak
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