P
Pieter
Hi,
We have written a cache, which can have different behaviours. One of these
is a WeakReference-Cache. The purpose is that, once an object isn't referred
anymore in the application, it should dissappear from the cache.
This works almost always fine, but not for some objects, and I can't find
out why. For some reason, even when I do a "MyObject = Nothing" and a
"GC.Collect", it still has its "WeakReference.IsAlive = True"...
Anybody knows why this happens? And what can I do about it? Should I
implement IDisposable to all my objetcs? And how does that work? Do I have
to do anything special in the overriden Dispose-method?
Thanks a lot in advance,
Pieter
This is how we did the GC.Collect and the removal of the
not-anymore-used-objects...
Private Shared Sub GarbageCollect()
Dim lstID As New List(Of Integer)
GC.Collect() 'premier collect
GC.WaitForPendingFinalizers() 'attend la fin du thread
GC.Collect() 'dexième collect pour tout enlever
GC.WaitForPendingFinalizers() 'attend la fin du thread
For Each i As Integer In dicCacheWeakReference.Keys
If Not dicCacheWeakReference(i).IsAlive Then
lstID.Add(i) 'si l'objet n'existe plus, l'ajoute dans la
liste à effacer
End If
Next
For Each intID As Integer In lstID
dicCacheWeakReference.Remove(intID) 'efface les reférences morte
du cache
Next
End Sub
We have written a cache, which can have different behaviours. One of these
is a WeakReference-Cache. The purpose is that, once an object isn't referred
anymore in the application, it should dissappear from the cache.
This works almost always fine, but not for some objects, and I can't find
out why. For some reason, even when I do a "MyObject = Nothing" and a
"GC.Collect", it still has its "WeakReference.IsAlive = True"...
Anybody knows why this happens? And what can I do about it? Should I
implement IDisposable to all my objetcs? And how does that work? Do I have
to do anything special in the overriden Dispose-method?
Thanks a lot in advance,
Pieter
This is how we did the GC.Collect and the removal of the
not-anymore-used-objects...
Private Shared Sub GarbageCollect()
Dim lstID As New List(Of Integer)
GC.Collect() 'premier collect
GC.WaitForPendingFinalizers() 'attend la fin du thread
GC.Collect() 'dexième collect pour tout enlever
GC.WaitForPendingFinalizers() 'attend la fin du thread
For Each i As Integer In dicCacheWeakReference.Keys
If Not dicCacheWeakReference(i).IsAlive Then
lstID.Add(i) 'si l'objet n'existe plus, l'ajoute dans la
liste à effacer
End If
Next
For Each intID As Integer In lstID
dicCacheWeakReference.Remove(intID) 'efface les reférences morte
du cache
Next
End Sub