• 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: GC pros and cons
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: GC pros and cons


  • Subject: Re: GC pros and cons
  • From: Michael Ash <email@hidden>
  • Date: Thu, 25 Jun 2009 10:37:45 -0400

On Thu, Jun 25, 2009 at 3:54 AM, Peter Duniho<email@hidden> wrote:
> In a GC system, the fact that an object hasn't been collected yet doesn't
> interfere with future allocations.  All it means is that the GC hasn't
> gotten around to collecting the object yet.  If and when a new object is
> required, and if the GC hasn't yet gotten around to collecting dead
> (unreachable) objects, and if there is not enough space to fulfill the new
> object, at that point in time the GC _will_ start working on collecting dead
> objects.
>
> You're not going to see a memory allocation failure simply because of
> non-determinism in the garbage collector.

That may be the theory, Apple's ObjC collector does *not* trigger on
allocation errors (at least not reliably or sufficiently, and as such
it is possible to outrun the collector by creating a large number of
objects in a tight loop.

This program demonstrates the problem:

#import <Foundation/Foundation.h>

int main( int argc, char **argv )
{
    objc_startCollectorThread();

    while(1)
        [NSMutableData dataWithLength:100000000];

    return 0;
}

After a while it started to spew out errors like this:

a.out(78814,0xa0160720) malloc: *** mmap(size=125001728) failed (error code=12)
*** error: can't allocate region
*** set a breakpoint in malloc_error_break to debug

I will freely admit that the above test program is a deeply
pathological case and you're highly unlikely to run into this in a
real application, however it is at least possible.

Mike
_______________________________________________

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 pros and cons
      • From: Michael Ash <email@hidden>
References: 
 >Re: GC pros and cons (From: Quincey Morris <email@hidden>)
 >Re: GC pros and cons (From: Chris Idou <email@hidden>)
 >RE: GC pros and cons (From: Jeff Laing <email@hidden>)
 >Re: GC pros and cons (From: "Stephen J. Butler" <email@hidden>)
 >RE: GC pros and cons (From: Jeff Laing <email@hidden>)
 >Re: GC pros and cons (From: Quincey Morris <email@hidden>)
 >RE: GC pros and cons (From: Jeff Laing <email@hidden>)
 >Re: GC pros and cons (From: Peter Duniho <email@hidden>)

  • Prev by Date: Re: Amount of Arguments per Method
  • Next by Date: Re: icns to Icon\r
  • Previous by thread: Re: GC pros and cons
  • Next by thread: Re: GC pros and cons
  • Index(es):
    • Date
    • Thread