checking garbade collector

S

stef

Hello...

With that kind of function :

public static Date testDate(String StrDate)
{
SimpleDateFormat fmt;

f = new SimpleDateFormat("MM/dd/yyyy");
f.setLenient(false);

try
{
return fmt.parse(StrDate);
}
catch(ParseException e)
{
return null;
}
}

I suppose fmt will be destroyed by the garbage collector when I will
get out of the function.
But, Do you know a method to "see" when the garbage do this ?

Overall, do you know How can I just really see what's free and what is
not ?
May be with finalize, but not very cool...

Thanks...
 
O

Owen Jacobson

Hello...

With that kind of function :

public static Date testDate(String StrDate)
{
SimpleDateFormat fmt;

f = new SimpleDateFormat("MM/dd/yyyy");
f.setLenient(false);

try
{
return fmt.parse(StrDate);
}
catch(ParseException e)
{
return null;
}
}

I suppose fmt will be destroyed by the garbage collector when I will
get out of the function.
But, Do you know a method to "see" when the garbage do this ?

Overall, do you know How can I just really see what's free and what is
not ?
May be with finalize, but not very cool...

Thanks...

If you need to monitor the garbage collector at an object by object
level, use a heap profiler. I use YourKit, which allows me to compare
snapshots to show only the new (or only the retained) objects between
multiple generations; other people like jmp/tijmp.

If you only need to monitor specific objects, use one of the
Reference<T> subclasses and a reference queue to monitor when those
objects get collected.
 
R

Roedy Green

I suppose fmt will be destroyed by the garbage collector when I will
get out of the function.
But, Do you know a method to "see" when the garbage do this ?

fmt is a local variable. So when it goes out of scope there will no
more references to the SimpleDateFormatObject you created. The leaves
it vulnerable to garbage collection.

GC does not touch the SimpleDateFormat object. It just reclaims all
the objects that DO have references to them. See
http://mindprod.com/jgloss/garbagecollection.html

If you want to watch it die, you might be able to see it with a memory
profiler http://mindprod.com/jgloss/profiler.html
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,071
Latest member
MetabolicSolutionsKeto

Latest Threads

Top