PDA

Click to See Complete Forum and Search --> : Suppressing Finializers?


Dillinger4
Apr 17th, 2002, 03:19 PM
Does anyone if this can be done in Java? I have some resources that need to be cleaned up in a timely fashion and im having issues with the lag between when the object is no longer refrenced by the application and when the object is consumed by the GC. Ive been working with Visual Basic Net lately and ive found a way to suppress them.

Class Demo
Private m_disposed As Boolean

Public Sub Disposed()

If(Not m_disposed) Then
Finialize()
GC.SuppressFinialize(this)
m_disposed = True
End If
End Sub

Protected Overides Sub Finialize()
'perform any necessary clean up here
End Sub
End Class

crptcblade
Apr 17th, 2002, 03:51 PM
Maybe I don't understand correctly, but why can't you just call the System's gc() method to run the garbage collector?

:)

Dillinger4
Apr 17th, 2002, 04:13 PM
I thought about that, but i wasn't to sure if i wanted to explictly run the GC in order to clean up a small amount of memory. I was thinking that the application might incur a performance hit by explictly invoking the GC rather than calling the finalize method directly. Im still not quite sure why VB.Net has a way to suppress finializers since if the finialize method is called and memory is reclaimed the method should only be invoked once.