From owner-freebsd-questions@FreeBSD.ORG Wed Mar 10 13:44:07 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 212C61065673 for ; Wed, 10 Mar 2010 13:44:07 +0000 (UTC) (envelope-from alex@stangl.us) Received: from stangl.us (stangl.us [66.93.193.95]) by mx1.freebsd.org (Postfix) with ESMTP id DDD078FC1A for ; Wed, 10 Mar 2010 13:44:06 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by scout.stangl.us (Postfix) with ESMTP id 49B53B8C9; Wed, 10 Mar 2010 07:44:06 -0600 (CST) X-Virus-Scanned: amavisd-new at stangl.us Received: from stangl.us ([127.0.0.1]) by localhost (scout.stangl.us [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id yu7AFScGH7eW; Wed, 10 Mar 2010 07:44:05 -0600 (CST) Received: by scout.stangl.us (Postfix, from userid 1001) id 37796B8C8; Wed, 10 Mar 2010 07:44:05 -0600 (CST) Date: Wed, 10 Mar 2010 07:44:05 -0600 From: Alex Stangl To: Nerius Landys Message-ID: <20100310134405.GA18632@scout.stangl.us> References: <560f92641003100100y6490cf3veb53ca0b11a90dcb@mail.gmail.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <560f92641003100100y6490cf3veb53ca0b11a90dcb@mail.gmail.com> User-Agent: Mutt/1.4.2.3i Cc: FreeBSD Mailing List 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: Wed, 10 Mar 2010 13:44:07 -0000 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