• 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: Bing Li <email@hidden>
  • Date: Sun, 12 Jun 2011 13:59:43 +0800

Der Stephen and Nick,

I solved the problem in this way.

- (void) Send
{
     NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
     char *message = [self createSendMessage];
     [self send:message];
     [pool drain];
}

It also works. How do you think about the solution?

Best,
Bing

On Sun, Jun 12, 2011 at 1:45 PM, Stephen J. Butler <email@hidden
> wrote:

> 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

References: 
 >Why Wasn't Memory Collected? (From: Bing Li <email@hidden>)
 >Re: Why Wasn't Memory Collected? (From: "Stephen J. Butler" <email@hidden>)

  • Prev by Date: Re: Why Wasn't Memory Collected?
  • Next by Date: Memory Management for XML Parsing
  • Previous by thread: Re: Why Wasn't Memory Collected?
  • Next by thread: Getting CGColor components
  • Index(es):
    • Date
    • Thread