Garbage collection

The garbage collection in Java can free the object no longer in use for me. But before that, does the garbage collection erase the data first (i.e. set the actual value to zero or some other value)?

I asked this question becasue I would like to find out:

I define some sensitive data in the applet. The garbage collection will free the memory as the applet is closed

If I use a special program to scan the memory, can I get back the data?

Thanks for help.

Jeff

[525 byte] By [code_man] at [2007-9-26 2:18:13]
# 1
That depends on the implementation of the virtual machine your application is running on. It's not specified by Sun that the VM should clear the memory. Probably nobody who implemented a VM thought about this, so I think you'll not be safe with this.Jesper
jesper1 at 2007-6-29 9:18:58 > top of Java-index,Core,Core APIs...
# 2
create a destructor in setting all your variable to null in your class when the applet call destroy call all the destructor.
jef06 at 2007-6-29 9:18:58 > top of Java-index,Core,Core APIs...
# 3
How about using java.lang.ref.PhantomReference?
WHOSNEXT at 2007-6-29 9:18:58 > top of Java-index,Core,Core APIs...
# 4
Using a PhantomReference won't help because you cannot reach the object from a PhantomReference. You could clear the fields in a finalizer, but there are no guarantees that a finalizer will run.
schapel at 2007-6-29 9:18:58 > top of Java-index,Core,Core APIs...
# 5
setting a variable to null doesn't delete the object in memory it just marks the used memory as free instantly instead of waiting the garbage collector to do so. I think you have to reset the primitive variables of your sensitive data.GreetsPuce
Puce at 2007-6-29 9:18:58 > top of Java-index,Core,Core APIs...