Re: Objective-C 2.0 on FreeBSD; garbage collection, anyone?
Scott Bennett benn...@cs.niu.edu wrote: If your program never frees any memory, then there is never any garbage to collect. Last I knew, garbage collection refers to tracking down and reclaiming allocated memory to which no valid references exist. The particular example given here is sufficiently trivial not to actually need GC -- it could easily free() before losing the (only) reference -- but keeping track can become extremely tricky in complex systems (hence the considerable effort that has been expended in designing and implementing GC systems). ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org
Re: (Update) Re: Objective-C 2.0 on FreeBSD; garbage collection, anyone?
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=/usr/local/gcc44 --with-system-zlib --enable-languages=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. No 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[]) { while (1) { Object *obj = [[Object alloc] init]; u_int h = [obj hash]; } return 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=/usr/opt/gcc44 --enable-objc-gc -enable-languages=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 = [[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). ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org
Re: Objective-C 2.0 on FreeBSD; garbage collection, anyone?
On Wed, 10 Mar 2010 11:14:25 -0800 Nerius Landys nlan...@gmail.com wrote: 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: http://developer.apple.com/mac/library/documentation/DeveloperTools/gcc-4.0.1/gcc/Objective_002dC-and-Objective_002dC_002b_002b-Dialect-Options.html 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 = 0; while (YES) { inx++; GarbageObj *obj = [[GarbageObj alloc] init]; [obj foo]; if (inx == 10) { inx = 0; sleep(1); } } return 0; } Unfortunately the memory usage is still steadily increasing. No garbage collection even if I compile with -fobjc-gc. :-( If your program never frees any memory, then there is never any garbage to collect. QED. Scott Bennett, Comm. ASMELG, CFIAG ** * Internet: bennett at cs.niu.edu * ** * A well regulated and disciplined militia, is at all times a good * * objection to the introduction of that bane of all free governments * * -- a standing army. * *-- Gov. John Hancock, New York Journal, 28 January 1790 * ** ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org
Objective-C 2.0 on FreeBSD; garbage collection, anyone?
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: http://developer.apple.com/mac/library/documentation/DeveloperTools/gcc-4.0.1/gcc/Objective_002dC-and-Objective_002dC_002b_002b-Dialect-Options.html . 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-4.2.5.20090325_2:lang/gcc42 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 ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org
Re: Objective-C 2.0 on FreeBSD; garbage collection, anyone?
On Wed, Mar 10, 2010 at 01:00:59AM -0800, Nerius Landys wrote: #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: http://developer.apple.com/mac/library/documentation/DeveloperTools/gcc-4.0.1/gcc/Objective_002dC-and-Objective_002dC_002b_002b-Dialect-Options.html 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. Alex ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org
Re: Objective-C 2.0 on FreeBSD; garbage collection, anyone?
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: http://developer.apple.com/mac/library/documentation/DeveloperTools/gcc-4.0.1/gcc/Objective_002dC-and-Objective_002dC_002b_002b-Dialect-Options.html 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 = 0; while (YES) { inx++; GarbageObj *obj = [[GarbageObj alloc] init]; [obj foo]; if (inx == 10) { inx = 0; sleep(1); } } return 0; } Unfortunately the memory usage is still steadily increasing. No garbage collection even if I compile with -fobjc-gc. :-( ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org
Re: Objective-C 2.0 on FreeBSD; garbage collection, anyone?
What is the content of the header file? File GarbageObj.h: #import Foundation/Foundation.h @interface GarbageObj : NSObject { } -(void) foo; @end File GarbageObj.m: #import GarbageObj.h @implementation GarbageObj -(void) foo { } -(void) dealloc { //printf(dealloc\n); [super dealloc]; } @end File GarbageMain.m: #import GarbageObj.h int main(int argc, const char *argv[]) { int inx = 0; while (YES) { inx++; GarbageObj *obj = [[GarbageObj alloc] init]; [obj foo]; if (inx == 100) { inx = 0; sleep(1); } //printf(before release\n); //[obj release]; //printf(after release\n); } return 0; } File GNUmakefile: include $(GNUSTEP_MAKEFILES)/common.make APP_NAME = garbagecollection garbagecollection_HEADERS = GarbageObj.h garbagecollection_OBJC_FILES = GarbageObj.m GarbageMain.m garbagecollection_RESOURCE_FILES = ADDITIONAL_OBJCFLAGS = -fobjc-gc include $(GNUSTEP_MAKEFILES)/application.make (I was building it as a tool before but now I tried app instead. Same thing really.) ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org