public inbox for java@gcc.gnu.org
 help / color / mirror / Atom feed
From: Andrew Haley <aph@redhat.com>
To: abhishek desai <abhi00@gmail.com>
Cc: java@gcc.gnu.org
Subject: Re: Calling the garbage collector.
Date: Mon, 27 Jul 2009 10:07:00 -0000	[thread overview]
Message-ID: <4A6D7C57.6080902@redhat.com> (raw)
In-Reply-To: <898285d30907270241h2a5a74abu8ae9a849399b8192@mail.gmail.com>

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.

  reply	other threads:[~2009-07-27 10:07 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-07-27  9:41 abhishek desai
2009-07-27 10:07 ` Andrew Haley [this message]
2009-07-27 14:43   ` BGB
2009-07-27 15:37 Chris Gray
2009-07-27 16:16 ` BGB

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4A6D7C57.6080902@redhat.com \
    --to=aph@redhat.com \
    --cc=abhi00@gmail.com \
    --cc=java@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).