It would not be easy to encapsulate your links in a simple
class MyOwnReference<T> {
public T ref;
public void set(T o) { ref = o; }
}
and create WeakReference<MyOwnReference<WhatEver>>?
I wonder if this can really be implemented without changing the JVM / environment.
No, you probably can't override WeakReference. This is a class supported by the JVM.
Are you sure instantiation WeakReferenceslows it down? I would not think to do
ref = new WeakReference(someObject);
instead of some
ref.set(anotherObject);
will be much more expensive.
source
share