• 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 Management for an Array
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Memory Management for an Array


  • Subject: Re: Memory Management for an Array
  • From: Alexander Spohr <email@hidden>
  • Date: Mon, 13 Jun 2011 21:31:40 +0200

The shown memory handling is wrong.

Am 13.06.2011 um 16:31 schrieb Bing Li:

> + (NSString *)read:(NSString *)xml Path:(NSString *)xPath

This methods signature should be read:path: with a lowercase p.


> {
>        // The Instruments indicated the following line got memory leaks.
> The amount of leaked memory was not large (about 400KB)

400 KB is a VERY large amount to leak.

>        NSXMLDocument *xmlDoc = [[NSXMLDocument alloc] initWithXMLString:xml
> options:NSXMLDocumentTidyXML error:NULL];
>
>        NSArray *nodes = [xmlDoc nodesForXPath:xPath error:NULL];

You hold a pointer to nodes but you do not retain them (usually no problem)

>        [xmlDoc release];

But here you release xmlDoc which was the only owner of nodes.
After this line nodes might be gone.
Use autorelease instead. That will keep xmlDoc alive long enough.

>        if ([nodes count] > 0)

This might kill you.

>        {
>                return [[nodes objectAtIndex:0] stringValue];

This as well.

>        }
>        else
>        {
>                return @"";
>        }
> }


_______________________________________________

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: 
 >Memory Management for an Array (From: Bing Li <email@hidden>)
 >Re: Memory Management for an Array (From: Scott Ribe <email@hidden>)
 >Re: Memory Management for an Array (From: Bing Li <email@hidden>)

  • Prev by Date: Re: Memory Management for an Array
  • Next by Date: Re: Is it possible to create a Finder-like icon in Dock?
  • Previous by thread: Re: Memory Management for an Array
  • Next by thread: Re: Memory Management for an Array
  • Index(es):
    • Date
    • Thread