You are hereBlogs / meck's blog / Java SoftReference
Java SoftReference
Here is some post for all Java programmers out there: Today I've been coding an object pool, that enables instance sharing. It could be used for example, if you have an application with many strings storing the same character data.
Basic idea is: Store all strings in the object pool - but only virtually. The pool itself will not create new strings, if it already possesses an equivalent one.
Now there is one problem: There are references to the objects not only within the application, but also from inside the pool. If the garbage collector wants to delete some unreferenced objects, my pool references will always prevent him from doing so. First I was thinking about some release methods for my pool and some reference counting stuff. Then I finally dropped this C++ style concepts and remembered the good old SoftReferences, that we learned in the lessons with PH. Now everything is smooth and without memory headaches.
- meck's blog
- Login to post comments