Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 10 Mar 2010 11:14:25 -0800
From:      Nerius Landys <nlandys@gmail.com>
To:        Alex Stangl <alex@stangl.us>
Cc:        FreeBSD Mailing List <freebsd-questions@freebsd.org>
Subject:   Re: Objective-C 2.0 on FreeBSD; garbage collection, anyone?
Message-ID:  <560f92641003101114l289d8f7aje8d49b4e68e1fe21@mail.gmail.com>
In-Reply-To: <20100310134405.GA18632@scout.stangl.us>
References:  <560f92641003100100y6490cf3veb53ca0b11a90dcb@mail.gmail.com> <20100310134405.GA18632@scout.stangl.us>

next in thread | previous in thread | raw e-mail | index | archive | help
>> I am compiling this program and running it, and without the "release"
>> calls there, it certainly is using up more and more memory every
>> second. =A0Definitely no garbage collection happening. =A0I then modifie=
d
>> the GNUmakefile to make sure that the option "-fobjc-gc" was being
>> passed to gcc, and verbose output from make assured me that this was
>> the case. =A0However, my program sill did not garbage collect (3 gigs of
>> RAM, then a segfault). =A0I then tried the gcc option "-fobjc-gc-only"
>> and gcc42 reported that it did not recognize that option. =A0The options
>> are described here:
>> http://developer.apple.com/mac/library/documentation/DeveloperTools/gcc-=
4.0.1/gcc/Objective_002dC-and-Objective_002dC_002b_002b-Dialect-Options.htm=
l
>
> While I am not very familiar with Objective C, I can tell you that GC
> generally runs in the background, using idle time to scavenge memory.
> (It's not counted pointers, synchronously freeing memory immediately.)
> So if you race to allocate memory in an infinite loop like this, you are
> destined to exhaust memory, GC or no, unless the runtime is designed to
> force a GC on alloc in low memory conditions.
>
> Try putting some sort of sleep in the middle of your loop and see if GC
> kicks in and you get more of a sawtooth memory usage pattern.

Well thanks for that advice.  My new program looks like this:

#import "GarbageObj.h"

int main(int argc, const char *argv[]) {
  int inx =3D 0;
  while (YES) {
    inx++;
    GarbageObj *obj =3D [[GarbageObj alloc] init];
    [obj foo];
    if (inx =3D=3D 100000) {
      inx =3D 0;
      sleep(1);
    }
  }
  return 0;
}



Unfortunately the memory usage is still steadily increasing.  No
garbage collection even if I compile with "-fobjc-gc".  :-(



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?560f92641003101114l289d8f7aje8d49b4e68e1fe21>