• 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
GC Seems To Never Kick In
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

GC Seems To Never Kick In


  • Subject: GC Seems To Never Kick In
  • From: Karl Moskowski <email@hidden>
  • Date: Thu, 12 Mar 2009 11:32:04 -0400

All this recent talk about GC here on cocoa-dev and on the Obj-C mailing list has come at an opportune time.

I'm working on a file compression framework that's GC-only and 32-bit. It reads a file using NSFileHandle 256KB at a time into an NSData object, processes each object into another NSData object, and writes the result to the new file via another NSFileHandle.

If I create a Foundation tool Xcode project, turn on GC and add my FW, then put something like this in main, it works fine, even if the file is > 5 GB.
int main (int argc, const char * argv[]) {
objc_startCollectorThread();
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
NSString *path = @"path/to/file.ext";
[MyClass processMethod:path];
[pool drain];
return 0;
}
GC kicks in periodically and keeps memory usage to a reasonable level.


However, in when I use the FW in a GC-enabled Cocoa app, it sometimes fails if I call the process: method either on the main thread or another one. According to Activity Monitor, both real memory and VM grow to many GB. Sometimes GC kicks in and real memory shrinks to a few MB then starts to grow again. However, sometimes it just grows, and I get the "malloc mmap failed (error code=12)" message.

If I add something like this to the method's processing loop
	if (++block % 1000 == 0)
		objc_collect(OBJC_EXHAUSTIVE_COLLECTION);
memory usage stays reasonable in the Cocoa app.

I've tried other options in various combinations (e.g. objc_collect(OBJC_COLLECT_IF_NEEDED) and objc_clear_stack(OBJC_CLEAR_RESIDENT_STACK)), but only the above seems to help.

Any idea why GC seems to work automatically in a Foundation tool, but in a Cocoa app it sometimes needs manual invocation?

----
Karl Moskowski <email@hidden>
Voodoo Ergonomics Inc. <http://voodooergonomics.com/>

Attachment: smime.p7s
Description: S/MIME cryptographic signature

_______________________________________________

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: GC Seems To Never Kick In
      • From: Bill Bumgarner <email@hidden>
  • Prev by Date: Re: Help, I need a jedi memory master with time and patience to help me here.
  • Next by Date: Re: Is cascading Nib Loading from -awakeFromNib permissible?
  • Previous by thread: Re: Help, I need a jedi memory master with time and patience to help me here.
  • Next by thread: Re: GC Seems To Never Kick In
  • Index(es):
    • Date
    • Thread