NSString Memory Management / NSAutoreleaseNoPool leaking warning
NSString Memory Management / NSAutoreleaseNoPool leaking warning
- Subject: NSString Memory Management / NSAutoreleaseNoPool leaking warning
- From: David Harper <email@hidden>
- Date: Fri, 25 May 2007 09:18:48 -0400 (EDT)
Hi,
I'm sure this is a problem everyone encounters and I think I'm getting close to the solution. I've been programming in C++ for the last few years so (I guess) I need a quick refresher on ObjC memory management.
I have a class called "Variable" that stores information about a numerical variable for my application. It stores a (NSString *)name, and a (NSString *)unit. There are several factory classes for this class that call the class' setName, setValue, setUnit and setKnown methods using either the information passed in or default information.
The problem occurs when I try to call the toString method I've created - I get the following warning:
2007-05-25 09:02:38.408 IterationA[1842] *** _NSAutoreleaseNoPool(): Object 0x7b00c of class NSCFString autoreleased with no pool in place - just leaking
Some research led me to change my setUnit and setString methods similarly; originally they were written as follows:
-(void) setUnit:(NSString *)_unit {
unit = _unit;
}
and I changed them to
-(void) setUnit:(NSString *)_unit {
if (unit != _unit) {
[unit release];
unit = [_unit retain];
}
}
This did not solve the problem. My toString method simply appends the unit after the variable name. It has exactly 1 line, and this line is what displays the above warning in the console. I've tried a few different things, none of which work. Should I be managing memory similarly in the classes that invoke this toString method?
return [[name stringByAppendingString:unit] retain];
return [[name stringByAppendingString:unit] autorelease];
return [name stringByAppendingString:unit];
Thanks,
-Dave Harper
_______________________________________________
Cocoa-dev mailing list (email@hidden)
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:
This email sent to email@hidden