Objective-C 2.0 on FreeBSD; garbage collection, anyone?

Nerius Landys nlandys at gmail.com
Wed Mar 10 09:01:01 UTC 2010

Running FreeBSD 8.0 32 bit PAE kernel, latest ports.

My current hobby is to experiment more with Objective-C.  I'm
rewriting some of my old Java code in Objectve-C to get a better
feeling for how this language works.

I'm finally able to write, compile, and run Objective-C programs after
learning about this the whole day.  i noticed that the gcc42 compiler
from ports is necessary as it contains the parts that are able to
compile Objective-C.  I realized that gcc43, gcc44, and gcc45 from
ports are _not_ able to compile Objective-C.

So my real question is this.  The supposed feature called "garbage
collection" that eliminates the need for "retain" and "release" syntax
in Objective-C - has anyone gotten it to work?  Frankly, I'm not even
sure if Objective-C framework on my FreeBSD server is supporting
Objective-C 2.0 or an older version; I have not gotten as far as
knowing which language constructs exist in 2.0 but not in earlier
versions.  But for right now I'm just trying to get automatic garbage
collection to work, which I know is a new feature in 2.0.

So, I've written a simple program that instantiates objects over and
over again, and loses references to them.  Like so:

#import "GarbageObj.h"

int main(int argc, const char *argv[]) {
  while (YES) {
    GarbageObj *obj = [[GarbageObj alloc] init];
    [obj foo]; // foo is does literally nothing.
  return 0;

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.  Definitely no garbage collection happening.  I then modified
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.  However, my program sill did not garbage collect (3 gigs of
RAM, then a segfault).  I then tried the gcc option "-fobjc-gc-only"
and gcc42 reported that it did not recognize that option.  The options
are described here:

So, I can't really try the newer compilers from ports because they
don't do Objective-C, and even so, I don't know if that would have any
effect on garbage collection.

Has anyone had success in writing Objectve-C programs on FreeBSD that
have automated garbage collection?  Does anyone know if this is
Objective-C 2.0 I'm dealing with?  How do I get this to work?  For
reference, here is a diff of packages installed today as a result of
trying out Objective-C:

> aspell-0.60.6_2:textproc/aspell
> cups-client-1.4.2_4:print/cups-client
> ffcall-1.10_1:devel/ffcall
> fontconfig-2.8.0,1:x11-fonts/fontconfig
> gcc-
> giflib-nox11-4.1.6:graphics/giflib
> gnustep-back-0.17.1_1:x11-toolkits/gnustep-back
> gnustep-base-1.19.3:lang/gnustep-base
> gnustep-gui-0.17.1_1:x11-toolkits/gnustep-gui
> gnustep-make-2.2.0_1:devel/gnustep-make
> gnutls-2.8.3:security/gnutls
> jbigkit-1.6:graphics/jbigkit
> libXft-2.1.14:x11-fonts/libXft
> libXrender-0.9.4_1:x11/libXrender
> libaudiofile-0.2.6_1:audio/libaudiofile
> libgmp-4.3.2:math/libgmp4
> mpfr-2.4.2:math/mpfr
> portaudio-19.20071207:audio/portaudio2
> renderproto-0.9.3:x11/renderproto
> tiff-3.9.2_1:graphics/tiff

- Nerius

More information about the freebsd-questions mailing list