• 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: Memory Leak with NSMutable String
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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.

  • Follow-Ups:
    • Re: Memory Leak with NSMutable String
      • From: "Alexander F. Hartner" <email@hidden>
References: 
 >Memory Leak with NSMutable String (From: "Alexander F. Hartner" <email@hidden>)

  • Prev by Date: Re: Memory Leak with NSMutable String
  • Next by Date: Re: NSNumber numberWithBool ?
  • Previous by thread: Re: Memory Leak with NSMutable String
  • Next by thread: Re: Memory Leak with NSMutable String
  • Index(es):
    • Date
    • Thread