[Gc] Problem with finalizers

Lothar Scholz scholz at scriptolutions.com
Wed May 2 18:08:40 PDT 2007


Hello Bruce,

Thursday, May 3, 2007, 6:26:15 AM, you wrote:

BH> Return-Path: <bruce.hoult at gmail.com>
BH> X-Original-To: scholz at scriptolutions.com
BH> Delivered-To: v03441615 at dd2300.kasserver.com
BH> Received: from wr-out-0506.google.com (wr-out-0506.google.com [64.233.184.233])
BH>         by dd2300.kasserver.com (Postfix) with ESMTP id D1A081142D9
BH>         for <scholz at scriptolutions.com>; Thu,  3 May 2007 01:26:18 +0200 (CEST)
BH> Received: by wr-out-0506.google.com with SMTP id i30so316545wra
BH>         for <scholz at scriptolutions.com>; Wed, 02 May 2007 16:26:17 -0700 (PDT)
BH> DKIM-Signature: a=rsa-sha1; c=relaxed/relaxed;
BH>         d=gmail.com; s=beta;
BH>        
BH> h=domainkey-signature:received:received:message-id:date:from:sender:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references:x-google-sender-auth;
BH>        
BH> b=K7/eNafLcBwen0fzZkqp7RHuiNaRWbozidgv8MQJ6b1gaLzKXflHZ6kq4nWxN5/de0YvQxQw8E+5G31gIIwelRZXhJZVVm3cbv1PgcjLGnnvgpAve55V9SRCGn2/MslnZON/7bOJAgsf7GI3EWMRDIpSLKMd6NCBQe4DqJFBWJA=
BH> DomainKey-Signature: a=rsa-sha1; c=nofws;
BH>         d=gmail.com; s=beta;
BH>        
BH> h=received:message-id:date:from:sender:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references:x-google-sender-auth;
BH>        
BH> b=gg7TMpoiCGWlQddePTkRfMowT6Zu0fSaHn36vX2+rSge8oMI+h7DIact/BBXcC/LmhEwu4AbUW22/+JcypCjSAfgnLBzFndgWKCdAMBwdrR3BRz4NiP6TuA8ZQhf993Z/e0tWCFgtSrtujwybSkNwRm5PUdXAGCUn0txk9M6zuA=
BH> Received: by 10.115.19.16 with SMTP id w16mr441929wai.1178148375546;
BH>         Wed, 02 May 2007 16:26:15 -0700 (PDT)
BH> Received: by 10.114.159.5 with HTTP; Wed, 2 May 2007 16:26:15 -0700 (PDT)
BH> Message-ID:
BH> <391c06200705021626qf70f342lf9798f9978d218be at mail.gmail.com>
BH> Date: Thu, 3 May 2007 11:26:15 +1200
BH> From: "Bruce Hoult" <bruce at hoult.org>
BH> Sender: bruce.hoult at gmail.com
BH> To: "Lothar Scholz" <scholz at scriptolutions.com>
BH> Subject: Re: [Gc] Problem with finalizers
BH> Cc: gc at napali.hpl.hp.com
BH> In-Reply-To: <747585064.20070503061537 at scriptolutions.com>
BH> MIME-Version: 1.0
BH> Content-Type: text/plain; charset=UTF-8; format=flowed
BH> Content-Transfer-Encoding: 7bit
BH> Content-Disposition: inline
BH> References: <747585064.20070503061537 at scriptolutions.com>
BH> X-Google-Sender-Auth: 6324ee2373be0930

BH> On 5/3/07, Lothar Scholz <scholz at scriptolutions.com> wrote:
>> i have written a test program that works fine. It just allocates 400
>> objectes in a loop 200 of them having finalizers. This loop is
>> repeated many times. No references to create objects are held after
>> the loop.
>>
>> Now the strange behaviour:
>>
>> Without finalizers its fast, but with finalizers the whole app stops
>> many times in the gc (as i guess) for seconds. Instead of 200 ms it
>> takes about 22 sec to finish. The finalizer function is empty and
>> there is no CPU load during the stops.

BH> I've got $100 says you're swapping.

Good advise for you: Be more carefull with your money :-)

The program just takes 5 MB on a 2 GB (Core2Duo) system. CPU usage is
below 5% with a peak at 9%.
I wouldn't be surprised if somethings happen or the whole thing
deadlocks. But it just stops for a few seconds and then continues.
And it's just the one  i uncomment the

"GC_register_finalizer(obj,my_finalizer_proc,my_client_data,NULL,NULL);"

line it all works fine.

BH> It takes memory to record the fact than an object has a finalizer.
BH> Having a finalizer prevents objects from being collected in the first
BH> GC after they become unreferenced, and they have to stay until the 2nd
BH> one.

Maybe Hans can tell me if it is okay to call GC_free from inside the
finalizer to tell the GC that it is not referenced again.

I also tried it with 'GC_finalize_on_demand' set to 0 and 1. No
difference in behaviour.


-- 
Best regards,
 Lothar Scholz                mailto:scholz at scriptolutions.com



More information about the Gc mailing list