• 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: Why Wasn't Memory Collected?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Why Wasn't Memory Collected?


  • Subject: Re: Why Wasn't Memory Collected?
  • From: "Stephen J. Butler" <email@hidden>
  • Date: Sun, 12 Jun 2011 00:45:51 -0500

On Sat, Jun 11, 2011 at 1:03 PM, Bing Li <email@hidden> wrote:
>        NSData *data = [xmlDoc XMLData];
>        NSString *xmlStr = [[[NSString alloc] initWithData:data
> encoding:NSUTF8StringEncoding] autorelease];
>        xmlStr = [xmlStr stringByAppendingString:@"\n"];
>        const char *xmlChar = [xmlStr UTF8String];
>
>        [xmlDoc release];
>        return xmlChar;
> }

If you're using your own autorelease pools now, be careful about the
lifetime of your return value (xmlChar)! It will only live as long as
xmlStr lives. For example, this would be incorrect:

NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
const char *str = [self createSendMessage:...];
[pool release];
// do something with str

You'll want to strdup() the return value to make sure it lives after
the pool is released, but then you also need to remember to free()
your strdup() value.
_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please 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

  • Follow-Ups:
    • Re: Why Wasn't Memory Collected?
      • From: Bing Li <email@hidden>
References: 
 >Why Wasn't Memory Collected? (From: Bing Li <email@hidden>)

  • Prev by Date: Re: Why Wasn't Memory Collected?
  • Next by Date: Re: Why Wasn't Memory Collected?
  • Previous by thread: Re: Why Wasn't Memory Collected?
  • Next by thread: Re: Why Wasn't Memory Collected?
  • Index(es):
    • Date
    • Thread