From owner-freebsd-questions@FreeBSD.ORG Fri Mar 12 04:15:57 2010 Return-Path: Delivered-To: questions@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id D7A3B106564A for ; Fri, 12 Mar 2010 04:15:57 +0000 (UTC) (envelope-from nlandys@gmail.com) Received: from mail-pv0-f182.google.com (mail-pv0-f182.google.com [74.125.83.182]) by mx1.freebsd.org (Postfix) with ESMTP id 9E2528FC15 for ; Fri, 12 Mar 2010 04:15:57 +0000 (UTC) Received: by pvg3 with SMTP id 3so344027pvg.13 for ; Thu, 11 Mar 2010 20:15:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:in-reply-to:references :date:message-id:subject:from:to:content-type :content-transfer-encoding; bh=ZHRAlwZOfkfkQSZGccwZETKxnq0agtvWQ3vm4edqJlo=; b=xC3HAeXvN/9rzXLcYOs1nbN1q1ThEyC3O5BxvyxoAmI+YaC3Zm3rFakKPtOS0zs727 hS2RPQ0BTQDOrLufVQ/h9B9bS0YZ45QshnzmMDMgZzlKg6z+ZIAr6Unmcm+Af+WbSQ6q MqSU5d+Ly7DkV9KF/jgMn2B41K5uZmDwZZ2LE= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type:content-transfer-encoding; b=WYOMyT9zgtUbex98pIYrYnBkiP5n/LUPZrEvIkTsDAKXjfyifufNkCvIo4/B8wyW5U ofLWg7qkJFDybxZDYlAv+l8O2WGOsicMbvTSZNajBtDAD6eeaTyS8poY2tI3688op4kt zKEzQc2FwzJdcGDV1CxCGABIygGTGouzm9z5E= MIME-Version: 1.0 Received: by 10.141.23.17 with SMTP id a17mr2413354rvj.157.1268367357049; Thu, 11 Mar 2010 20:15:57 -0800 (PST) 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> Date: Thu, 11 Mar 2010 20:15:56 -0800 Message-ID: <560f92641003112015j34e4bc64q106f36cd7d408298@mail.gmail.com> From: Nerius Landys To: dg17@penx.com, questions@freebsd.org Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Cc: Subject: Re: (Update) Re: Objective-C 2.0 on FreeBSD; garbage collection, anyone? X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 12 Mar 2010 04:15:57 -0000 > 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 > #import > > 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 #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 @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).