SoftReferences and WeakReferences have different semantics:
Objects referenced through weak references go away as soon as you don't have
any strong references to them (at the next GC pass).
Objects referenced through soft references go away when the memory starts to
fill up, if they don't have strong references pointing to them. So, they
don't go away at the next GC pass if the memory pressure is low.
So, soft references are much more practical than weak reference for caching,
and you will need to do some extra work (keeping extra strong references and
breaking them when memory pressure gets high) if you want to reproduce the
soft reference behavior with weak references.
2 reasons why J# does not have soft references:
* it is based on JDK 1.1.4, which did not have soft references.
* the .NET framework (even 2.0) only provides weak references.
Bruno
"Nathan Baulch" <nathan.baulch@gmail.com> a écrit dans le message de news:
umxh5JxQGHA.1556@TK2MSFTNGP09.phx.gbl...
[quoted text, click to view] > I'm trying to compile a Java project in Visual Studio however it would
> seem that J# doesn't have an implementation of the
> java.lang.ref.SoftReference class (which I imagine would be a simple
> wrapper over the top of a System.WeakReference).
>
> I'm trying to keep the project as close as possible to pure Java (ie, only
> reference vjslib.dll and not mscorlib.dll) however it looks like I'll have
> to contaminate it by migrating the SoftReferences to WeakReferences.
>
>
> Nathan
>