From owner-freebsd-questions@FreeBSD.ORG Wed Mar 10 19:14:28 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 0A72B106566C for ; Wed, 10 Mar 2010 19:14:28 +0000 (UTC) (envelope-from nlandys@gmail.com) Received: from mail-qy0-f183.google.com (mail-qy0-f183.google.com [209.85.221.183]) by mx1.freebsd.org (Postfix) with ESMTP id B28E68FC1D for ; Wed, 10 Mar 2010 19:14:27 +0000 (UTC) Received: by qyk14 with SMTP id 14so3830916qyk.9 for ; Wed, 10 Mar 2010 11:14:27 -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:cc:content-type :content-transfer-encoding; bh=hBSkdTaw9Y9lMx+sUxyt2DW/PieIv5jEoJ0s+zPo+YQ=; b=nvcYJEAdGLn4KA4fYKkHevn+tF7pm7fQGS3Jy8CJHc+5xCzTw+68gBEGl976j/DzTn n4PLlP9xRedtHBLzaq1A0AJMyayuuQZf1cbiDaNKQIjyYUlJ0JAloUiMfkSc8C1xSMTQ ovkkbP6hnLpZ+c02jq95ji/lSCEAKyGr7ackI= 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 :cc:content-type:content-transfer-encoding; b=DOSsBRG56r05R+8nOhCsvQr/RUdIF8uEK0YFQYBWjnafr/01oiuu6ZlXKd4n4vkiic 6LLcWIYsp3YMJjyraU3n8vkFEE1CLOiWBsPEtj7GGpz+B/U8AMTVPlf76uxVq4E4y4Hm LLc5CjQRTK+f/3VCaLO4Ps9lQb0vAH7bHcPOU= MIME-Version: 1.0 Received: by 10.229.217.13 with SMTP id hk13mr1915032qcb.94.1268248465913; Wed, 10 Mar 2010 11:14:25 -0800 (PST) In-Reply-To: <20100310134405.GA18632@scout.stangl.us> References: <560f92641003100100y6490cf3veb53ca0b11a90dcb@mail.gmail.com> <20100310134405.GA18632@scout.stangl.us> Date: Wed, 10 Mar 2010 11:14:25 -0800 Message-ID: <560f92641003101114l289d8f7aje8d49b4e68e1fe21@mail.gmail.com> From: Nerius Landys To: Alex Stangl Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable 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 19:14:28 -0000 >> 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. =A0Definitely no garbage collection happening. =A0I then modifie= d >> 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. =A0However, my program sill did not garbage collect (3 gigs of >> RAM, then a segfault). =A0I then tried the gcc option "-fobjc-gc-only" >> and gcc42 reported that it did not recognize that option. =A0The 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.htm= l > > 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 =3D 0; while (YES) { inx++; GarbageObj *obj =3D [[GarbageObj alloc] init]; [obj foo]; if (inx =3D=3D 100000) { inx =3D 0; sleep(1); } } return 0; } Unfortunately the memory usage is still steadily increasing. No garbage collection even if I compile with "-fobjc-gc". :-(