The Artima Developer Community
Sponsored Link

Java Answers Forum
Garbage collection

6 replies on 1 page. Most recent reply: Jun 10, 2002 4:00 PM by Thomas SMETS

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 6 replies on 1 page
Sony.C.joy

Posts: 7
Nickname: sonycjoy
Registered: Jun, 2002

Garbage collection Posted: Jun 3, 2002 5:33 AM
Reply to this message Reply
Advertisement
Can we set a time limit for objects for garbage collection ?


Galahady Gao

Posts: 4
Nickname: galahady
Registered: Jun, 2002

Re: Garbage collection Posted: Jun 4, 2002 3:55 AM
Reply to this message Reply
As far as I know, Java programming langugae doesn't
provide any methods to control the garbage
collectoin process.

But, there is a System.gc(). Although System.gc()
doesn't guarantee the JVM will start the GC(Garbage
Clollection) at once, it really is able to 'urge'
JVM to do GC.

So, based on this point, you can make a timer thread
to call System.gc() at a specific interval.

Hope the GC timer is what you want!

Thomas SMETS

Posts: 307
Nickname: tsmets
Registered: Apr, 2002

Re: Garbage collection Posted: Jun 4, 2002 2:19 PM
Reply to this message Reply
Could you rephrase your question ?
What do you mean by setting a time limit to GC ?
>
> Can we set a time limit for objects for garbage
> collection ?
>


The timie during which the GC is run ?
You want to do some caching & therefore limit the time some references are hold ?
For the first, you have no interaction but limit the memory size / heap size & increase you own (application level) Threads.
For the second you may need to use Weak / Phantom / Soft References !

.. something else ... ?


Thomas SMETS,
SCJP2 - Brussels

Sony.C.joy

Posts: 7
Nickname: sonycjoy
Registered: Jun, 2002

Re: Garbage collection Posted: Jun 5, 2002 3:43 AM
Reply to this message Reply
What i want is that i want an object to be garbage collected after a specified period of time.
The time will be specified manually

Thomas SMETS

Posts: 307
Nickname: tsmets
Registered: Apr, 2002

Re: Garbage collection Posted: Jun 5, 2002 1:42 PM
Reply to this message Reply
>
> What i want is that i want an object to be garbage
> collected after a specified period of time.
> The time will be specified manually
>

Well, you could do that but I'am not sure you'd really wanna do that (really)!
Here is what you should do !
As soon an object is not needed anymore you could have it referenced by an Object-array... Simply smthg declared
Object[] o;
not more no less.
You then just do a :
public void nullyfy ()
{
   try
   {
     for ( int i = 0;
            ; // No Exit condition if the loop is to run over a huge array 
          i++) // This is for efficiency reasons
       o[i] = null; // Dereferencing 
   } catch (NullPointerException NPEe)
   {
      // Loop is ended !
   }
}

I would however play with the different types of references,instead !

Tip :
All these could very simply happen on a Singeltonned version of a class... I find the need overwhelmingly complicated for what you may actually want, though ... it's your choice !



Thomas SMETS,
SCJP2 - Brussels

Bhogi

Posts: 1
Nickname: bhogi
Registered: Jun, 2002

Re: Garbage collection Posted: Jun 10, 2002 4:06 AM
Reply to this message Reply
try calling the sleep() method in the finalize block to delay the possible Garbage Collection.

Thomas SMETS

Posts: 307
Nickname: tsmets
Registered: Apr, 2002

Re: Garbage collection Posted: Jun 10, 2002 4:00 PM
Reply to this message Reply
>
> try calling the sleep() method in the finalize block
> to delay the possible Garbage Collection.
>

Simply calling sleep will never work as such.
You first need to make sure you invoked the System.runFinalizer ();
You may then try to reduce the propagation of the GC process but it's already running then !
th eobject will there for be marked as ready for GC !

Thomas SMETS,
SCJP2 - Brussels

Flat View: This topic has 6 replies on 1 page
Topic: NoClassDefFoundError....What's Wrong ? Previous Topic   Next Topic Topic: Server

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use