it seems for me that in Java world there is much freedom
in controlling the garbage collector than in .NET: JDK
includes SoftReference and WeakReference classes,
while .NET supports only WeakReferences. Is there any way
to simulate soft references in .NET? Or why they are
missed?
I'm not a guru in .NET garbage collector, and I have a
problem: in my Java application there is a cache based on
soft references, and all works fine. When I ported the
application to the .NET, the cache becomes using weak
references, and it's behavior is now far from good: weak
references die too often, so the application needs to
rebuild cached object which is time-consuming procedure.
Thanks in advance,
Dmitry
Then I or someone else may be able to offer suggestions on how to better
approximate them in .NET.
At the very least it does sound like something I would find useful.
Hope this helps
Jay
"Dmitry Shaporenkov" <dsha...@yahoo.com> wrote in message
news:11f701c372bc$0d2480a0$a001...@phx.gbl...
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnpag/html/CachingBlock.asp
Granted its not SoftReferences per se.
Hope this helps
Jay
"Dmitry Shaporenkov" <dsha...@yahoo.com> wrote in message
news:11f701c372bc$0d2480a0$a001...@phx.gbl...
The closest thing I can think to SoftReferences would be long WeakReferences
to finalizable objects.
In .NET you have 2 kinds of WeakReference, and resurrection to play with.
For instance if you use long WeakReferences -- new WeakReference(o,true) --
and o has a Finalizer, then you get to decide, in O's finalizer whether it's
time to die. If it's not time to die, then just
GC.ReRegisterForFinalize(this).
First off, merely using long WeakReferences to finalizable objects for your
cache will make them behave more like SoftReferences. A finalizable object
alway survives at least one GC, and thus gets promoted to Generation 1.
Generation 1 is collected less frequently than Generation 0, and only when
more memory is needed. Generation 2 is collected even less frequently than
Generation 1. So if you re-register for finalize just once then you're
guaranteed to survive into Generation 2 and will probably be around for a
good long while.
David