Date: Thu, 11 Mar 2010 20:15:56 -0800 From: Nerius Landys <nlandys@gmail.com> To: dg17@penx.com, questions@freebsd.org Subject: Re: (Update) Re: Objective-C 2.0 on FreeBSD; garbage collection, anyone? Message-ID: <560f92641003112015j34e4bc64q106f36cd7d408298@mail.gmail.com> In-Reply-To: <1268345410.13552.158.camel@btw.pki2.com> References: <560f92641003100100y6490cf3veb53ca0b11a90dcb@mail.gmail.com> <20100310134405.GA18632@scout.stangl.us> <560f92641003101114l289d8f7aje8d49b4e68e1fe21@mail.gmail.com> <1268345410.13552.158.camel@btw.pki2.com>
next in thread | previous in thread | raw e-mail | index | archive | help
> Sorry for the delay. Medical problem. > > Here's what I know. > > 1) Under FreeBSD 8.x OBJC APPEARS NOT to use garbage collection. I > looked at the source and the GC routines aren't defined anywhere and I > stepped through the assembly language and the allocation routing call > malloc(). There is a specific conditional in the FreeBSD compiler that > cloosed malloc() or GC_malloc() depending on whether a GC variable is > defined. > > 2) Even through you can specify -fobjc-gc on a compile line using the > FreeBSD compiler, it appears there is no warning issued if GC is not > enabled. > > 3) GCC 45 in the ports directory DOES NOT include OBJC. Neither does 44. > > 4) I downloaded GCC and compiled it this way: > > ../gcc-4.4.3/configure --disable-nls --disable-rpath > --prefix=3D/usr/local/gcc44 --with-system-zlib --enable-languages=3D"c,c > ++,objc" --enable-objc-gc > > I compiled an ObjC program this way: > > /usr/local/gcc44/bin/gcc -fobjc-gc -g -O prog.m -lobjc_gc -static > -pthread > > I checked and the GC routines are in there. > > I have a Core2 Quad, 8GB of RAM, and 32 GB of swap. I ran "a" program > (below). No swap activity. =A0No swap consumption. No increase in memory > consumption. Five minutes. It hasn't crashed. > > YMMV > > > #include <sys/types.h> > #import <objc/Object.h> > > int main(int argc, const char *argv[]) { > =A0while (1) { > =A0 =A0Object *obj =3D [[Object alloc] init]; > =A0 =A0u_int h =3D [obj hash]; > =A0} > =A0return 0; > } > Wow thanks, that really helps. I now understand more about how this stuff works. I'm kind of new to C programming in general, and library linking and all that sort of stuff. My gcc command is like this now: /usr/opt/gcc44/bin/gcc -o main Main.m MyObj.m -lobjc_gc -lpthread -static The "-static" is nice because my libobjc_gc.so is in a non-standard location on my system, namely /usr/opt/gcc44/lib/ , and so I don't have to specify LD_LIBRARY_PATH if I compile with "-static" (but as a result the binary is larger and takes more memory to run, by about 700 kilobytes). The "-lpthread" is necessary because pthreads are used as part of the garbage collection process. The "-lobjc_gc" is used instead of "-lobjc" to enable garbage collection. I compiled gcc 4.4.3 (downloaded directly from links on gcc.gnu.org) myself (not from ports), with ./configure --prefix=3D/usr/opt/gcc44 --enable-objc-gc -enable-languages=3D"c,c++,objc" My source code looks like this: Main.m --------------------- #import <pthread.h> #import "MyObj.h" int main(int argc, const char *argv[]) { while (YES) { MyObj *obj =3D [[MyObj alloc] init]; [obj hash]; } return 0; } MyObj.h ---------------------- #import <objc/Object.h> @interface MyObj : Object {} @end MyObj.m ---------------- #import "MyObj.h" @implementation MyObj @end I get no memory increases in my program. I have not tried to get garbage collection to work with GNUstep yet. It very well may not work, because the garbage collection is probably tied to objc_gc (for example instead of gnustep-base or gnustep-runtime or something like that). Like I said I don't know too much about C programming at this point. I do see a libgnustep-base.so in my GNUstep installation, but I don't see anything of the form *_gc.so. I'm going to write some programs just using Object, not using GNUstep at this point. I think I'll wait until I get an Apple and an iPhone before I try to use the other object classes (NSObject and friends).
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?560f92641003112015j34e4bc64q106f36cd7d408298>