• 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: garbage collection memory leak
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: garbage collection memory leak


  • Subject: Re: garbage collection memory leak
  • From: Bill Bumgarner <email@hidden>
  • Date: Thu, 18 Dec 2008 11:01:41 -0800

On Dec 17, 2008, at 3:16 PM, Michael Link wrote:
I'm trying to track down a memory leak even though I'm using garbage collection. I was curious what the "rc:" field means when using "info gc-roots" in gdb? It doesn't seem to correlate to the Retain Count when inspecting an address in Instruments and it doesn't seem to always correlate to using "info gc-references" in gdb. I would tend to assume that it would make more sense if it meant the retain count since that would explain why the root objects have something > 0.

rc refers to the CF level retain count. Under GC, CFRetain() and CFRelease() still maintain a retain count and the collector will not reap objects with a non-zero retain count.


After running about 40 NSURLConnections in an application and closing out everything so that only the menu bar is left I noticed that there are some objects not being collected that are definitely not being used anymore and should have been collected.

Some of the objects I noticed right away are NSXMLDocuments which are created right after a connection sends the - connectionDidFinishLoading: delegate message. The method looks like:

- (void)connectionDidFinishLoading:(NSURLConnection*)connection
{
NSError* error = nil;
NSString* string = [[NSString alloc] initWithData:connection.data encoding:NSUTF8StringEncoding];
NSXMLDocument* document = nil;


if (document = [[NSXMLDocument alloc] initWithXMLString:string options:[self options] error:&error]) {
... extract some NSStrings using objectsForXQuery:@"xs:string(/ some[1]/path[1])
... assign strings to NSManagedObject
}
}


the -connectionDidFinishLoading: runs on a background thread that is using NSRunLoop, so the stack should be cleared.

I was mistaken in my previous post. The main event loop clears the stack, but not regular old NSRunLoops.


You'll need to clear the stack with a stock NSRunLoop.

(<rdar://problem/6455869>).

I would guess that something in that thread has some objects laying around or possibly is falsely rooted on the stack? I'd be curious to find out any solutions on how to get these objects collected. After a few thousand NSURLConnections the leakage can be in the 100s of MBs.

Given that the rooting objects have non-zero retain counts, that is a source of the problem. The roots look like the XML document has some low level back references to the document that are also retained by something.


Odd.

Filed as bug #6452901

Thanks for the bug.

b.bum

_______________________________________________

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: 
 >garbage collection memory leak (From: Michael Link <email@hidden>)

  • Prev by Date: Re: Performance of calculation on float point numbers in a array • NSNumber in NSArray, or classic C array?
  • Next by Date: Re: a few Core Data questions: Predicates and document based app
  • Previous by thread: garbage collection memory leak
  • Next by thread: Menu & System Preference keyboard shortcuts weirdness.
  • Index(es):
    • Date
    • Thread