Calling the garbage collector.

BGB cr88192@hotmail.com
Mon Jul 27 14:43:00 GMT 2009


----- Original Message ----- 
From: "Andrew Haley" <aph@redhat.com>
To: "abhishek desai" <abhi00@gmail.com>
Cc: <java@gcc.gnu.org>
Sent: Monday, July 27, 2009 3:07 AM
Subject: Re: Calling the garbage collector.
> 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.
>
hmm...
maybe Java needs 'delete'?...
> Andrew.
>


More information about the Java mailing list

AltStyle によって変換されたページ (->オリジナル) /