I finally understood what weak references are for:
http://weblogs.java.net/blog/enicholas/archive/2006/05/understanding_w.html
Simply put, the referenced object (by one of the reference classes) can be claimed by the garbage collector at any time, and you wouldn`t have that object anymore. Why the hell would I want to use that, then?
The answer is simply: caching.
By doing some hack around the class SoftReference, you could have a caching mechanism that would delete objects from the cache when the Java VM needs more memory. Instead of crashing, you would lose some objects from the cache, which would have to be obtained later, but no big deal - that`s just a small performance penalty.
I would like to have that knowledge 5 years ago. It would have been useful.
NOTA: Era para ter saìdo no outro blog.
Nenhum comentário:
Postar um comentário