From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 5341 invoked by alias); 27 Jul 2009 10:07:35 -0000 Received: (qmail 5332 invoked by uid 22791); 27 Jul 2009 10:07:34 -0000 X-SWARE-Spam-Status: No, hits=-2.1 required=5.0 tests=AWL,BAYES_00,J_CHICKENPOX_46,SPF_HELO_PASS,SPF_PASS X-Spam-Check-By: sourceware.org Received: from mx2.redhat.com (HELO mx2.redhat.com) (66.187.237.31) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Mon, 27 Jul 2009 10:07:25 +0000 Received: from int-mx2.corp.redhat.com (int-mx2.corp.redhat.com [172.16.27.26]) by mx2.redhat.com (8.13.8/8.13.8) with ESMTP id n6RA7OQ2004397; Mon, 27 Jul 2009 06:07:24 -0400 Received: from ns3.rdu.redhat.com (ns3.rdu.redhat.com [10.11.255.199]) by int-mx2.corp.redhat.com (8.13.1/8.13.1) with ESMTP id n6RA7M8K003691; Mon, 27 Jul 2009 06:07:23 -0400 Received: from pearl.pink (vpn-12-149.rdu.redhat.com [10.11.12.149]) by ns3.rdu.redhat.com (8.13.8/8.13.8) with ESMTP id n6RA7LWe021814; Mon, 27 Jul 2009 06:07:21 -0400 Message-ID: <4A6D7C57.6080902@redhat.com> Date: Mon, 27 Jul 2009 10:07:00 -0000 From: Andrew Haley User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.1b3pre) Gecko/20090513 Fedora/3.0-2.3.beta2.fc11 Thunderbird/3.0b2 MIME-Version: 1.0 To: abhishek desai CC: java@gcc.gnu.org Subject: Re: Calling the garbage collector. References: <898285d30907270241h2a5a74abu8ae9a849399b8192@mail.gmail.com> In-Reply-To: <898285d30907270241h2a5a74abu8ae9a849399b8192@mail.gmail.com> Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-IsSubscribed: yes Mailing-List: contact java-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: java-owner@gcc.gnu.org X-SW-Source: 2009-07/txt/msg00070.txt.bz2 On 07/27/2009 11:41 AM, abhishek desai wrote: > Hi, > > I have a simple java program to test the garbage collection. It has > the two java files shown below. > > TestClass.java > > public class TestClass { > protected void finalize() throws Throwable { > System.out.println("Java TestClass finalizer called."); > } > } > > > HelloWorld.java > > import TestClass; > > class HelloWorld > { > public static void main(String args[]) { > System.out.println("HelloWorld\n"); > > TestClass a = new TestClass(); > a = null; > System.gc(); > } > } > > > When I compile this using javac to a class file and run the bytecode > using the 'java' interpreter, the finalize funtion for TestClass.java > is called. > When I compile the same set of files using gcj to machine code, the > finalizer is not called. Can any one tell me why this happens and what > I will have to do to get the finalizer called when object is no longer > used. The finalize will be called when the object is collected. When the object actually gets collected is not defined, and is not guaranteed to happen before the program exits. Also, there is no absolute guarantee that the object will ever be collected. Andrew.