Re: Memory Leak with NSMutable String
Re: Memory Leak with NSMutable String
- Subject: Re: Memory Leak with NSMutable String
- From: "Alexander F. Hartner" <email@hidden>
- Date: Mon, 26 Jan 2004 16:09:29 +0200
Thanks for your help. Does this mean that the memory used by these
NSMutableString will only be released once the NSAutoreleasePool is
released. Currently the memory usage seems to increase even though I am
only using one instance of NSMutableString. Would this problem go away
if instead of initialising the NSMutuableString with the initWith
method I would rather call init and then release it manually rather
then relying on auto release ?
Thanks
Alex
On 26 Jan 2004, at 15:32, Peter Maurer wrote:
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]
The memory never got freed so I tried doing it explicitly. Didn't seem
to make a difference
.
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.
_______________________________________________
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.