Re: Memory Leak with NSMutable String
Re: Memory Leak with NSMutable String
- Subject: Re: Memory Leak with NSMutable String
- From: Peter Maurer <email@hidden>
- Date: Mon, 26 Jan 2004 14:32:30 +0100
The following code uses as diagnosed with ObjectAlloc and MallocDebug
more and more memory. It seems that NSMutableString don't get properly
released. I am still quite new to Objective C and most likely am doing
something incredible stupid. Any suggestions are welcome.
See below...
void doOtherStuff()
{
NSMutableString *data = [NSMutableString stringWithCapacity:1000];
[data appendString:@"DATA"];
[data release];
Why do you release "data"? It was created as an autoreleased object and
you never retained it. If you want to release it immediately, use
[[NSMutableString alloc] initWithCapacity:1000].
printf("Interation \n");
}
int main (int argc, const char * argv[]) {
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
// insert code here...
NSLog(@"Hello, World!");
int counter=0;
for (counter=0; counter<1000000;counter++)
{
doOtherStuff();
}
[pool release];
This is where all your "data"s will be released, since they were
created as autoreleased objects. Did you expect something different?
Peter Maurer.
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.