In Java you don't do that. You leave it to the garbage collector to
clean up. Which , I think, may be a problem sometimes.
F.i. when you want to really really get rid of a password that was
stored i memory: you could set it to null, but that will not erase it,
only "mark" it for the GC to delete it "sometime, maybe"  ...
You canot control the GC in any way. You cannot force it to do it's
duties.
Even System.gc(); will not necessarily make it collect garbage.

So in most cases, don't worry about it:
Out of scope = out of mind = GC = will be dumped, maybe, some time.

In the password scenario, I'd explicitly overwrite it.

On Sep 4, 9:12 am, han <[EMAIL PROTECTED]> wrote:
> How about my scenario?
> It is not a good java code practice,isn't it?
> How can I destroy a object explicitly?
>
> BR
> Chen Han
>
> On Sep 4, 2:39 pm, ewer <[EMAIL PROTECTED]> wrote:
>
> > Hi,
>
> > On 4 Sep., 05:51, "CHEN HAN A" <[EMAIL PROTECTED]> wrote:
>
> > > Hi,
>
> > > I have experience for c++, but I con't find deconstruction function in
> > > java.
> > > i know java's garbage collection.
>
> > > But consider this scenario:
> > > I use class variable "count" to count the number of object and "count++"
> > > in constructor.
> > > When a object have to be destory, "count--" have to be execute.
> > > How can i do?
>
> > Have a look at the finalize method 
> > inhttp://java.sun.com/j2se/1.4.2/docs/api/java/lang/Object.html,
> > which you can overwrite.
>
> > But when the method is called, depends on the garbage collector. When
> > the garbage collector
> > run's, it detects unreferenced objects and destroys them. When this
> > occurs is not fixed.
>
> > HTH
> > Ewald
>
>

--~--~---------~--~----~------------~-------~--~----~
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/javaprogrammingwithpassion?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to