Re: java.lang.ref.SoftReference missing?

Tech-Archive recommends: Speed Up your PC by fixing your registry



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@xxxxxxxxx> a écrit dans le message de news:
umxh5JxQGHA.1556@xxxxxxxxxxxxxxxxxxxxxxx
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



.



Relevant Pages

  • Re: Can someone explain this weakref behavior?
    ... >> is more robust than simply incrementing and decrementing class variables ... >> immediately deleting the weak reference as soon as all references to the ... >> behavior of weak references? ... refcount of zero. ...
    (comp.lang.python)
  • A re-announce on GCs defects
    ... The need for weak reference makes the destruction delay logically incorrect. ... Weak references refer to references who do ... When all strong references to a target go out of their lifetime, ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: nss_ldap broken
    ... I had no idea that libpthread would be loaded then unloaded. ... I'm unsure how nss_ldap was built to depend on libpthread (or ... weak references (not definitions, like you see in our libc ... By making the pthread_* references weak, you don't need to be linked ...
    (freebsd-current)
  • Re: weakreferences - my understanding
    ... >for normal objects and weak references, ... >references get cleared in same situtations where normal objects become ... >addition to the requirement of clearing soft references before signaling ...
    (comp.lang.java.programmer)
  • Re: Resolve object pointer any use for this?
    ... So, all in all a very interesting technique, but unfortunately, no good ... By the way, weak references in .NET are not needed nearly as much, because ... ObjPtr for the object as the key. ...
    (microsoft.public.excel.programming)