Tuesday, March 6, 2007

Hard, Soft, Weak and Phantom

The title sounds so exciting until I explain I'm referring to Java references. I was asked to explain weak references in an interview. I'm so careful with my words I said I couldn't explain it well enough.

The sum total my knowledge is that I can create a WeakHashMap whereby the keys are weakly referenced, and thus objects are able to be garbage collected. I gather it might be useful for a caching, but I've always used third party caching implementations. And quite frankly, performance issues I encounter are generally latency, not memory problems.

Pardon the expression, but I thought this explanation was rather weak, so I passed.

Naturally I wish to rectify this abysmal lack of understanding, and I found a rather nice summary of the reference types here.

Soft references were previously unknown to me, although if the following is true they seem more useful that Weak; "in practice softly reachable objects are generally retained as long as memory is in plentiful supply".

0 comments: