From owner-freebsd-questions@FreeBSD.ORG Fri Mar 12 05:58:44 2010 Return-Path: Delivered-To: freebsd-questions@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 1397B106564A for ; Fri, 12 Mar 2010 05:58:44 +0000 (UTC) (envelope-from bennett@cs.niu.edu) Received: from mp.cs.niu.edu (mp.cs.niu.edu [131.156.145.41]) by mx1.freebsd.org (Postfix) with ESMTP id C3CEC8FC18 for ; Fri, 12 Mar 2010 05:58:43 +0000 (UTC) Received: from mp.cs.niu.edu (bennett@localhost [127.0.0.1]) by mp.cs.niu.edu (8.14.3/8.14.3) with ESMTP id o2C5weNQ022369; Thu, 11 Mar 2010 23:58:40 -0600 (CST) Date: Thu, 11 Mar 2010 23:58:40 -0600 (CST) From: Scott Bennett Message-Id: <201003120558.o2C5welE022368@mp.cs.niu.edu> To: freebsd-questions@freebsd.org, Nerius Landys Cc: Alex Stangl Subject: 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 05:58:44 -0000 On Wed, 10 Mar 2010 11:14:25 -0800 Nerius Landys 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 == 100000) { > 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 * **********************************************************************