Local database reading edition

Reference Objects and Garbage Collection

Reconstructed from database records, not a captured original forum layout. Dates and display names are retained as recorded; timezone and real-world identity are not inferred. Historical advice, contact details and offers are not current. Original markup is shown as inert text.

Forum index · Java - Basic

Opening post

administrator · 2001-02-12 18:25:28

Performance is one of the major architectural goal many organization, So I will recommend to use Soft Reference when, you don't know in advance whether you are going to reuse the object, but you might reuse it. In this scenario if you keep reference to the object, thinking you might reuse it, could possible that your application will never use it again. in that case you will cause a memory leak. Soft Reference helps the garbage collector to claim if memory in heap is going low, GC claims the oldest one first. The Rule is "Before throwing the OutOfMemoryException, GC has to clean all the Soft Reference ". This way programmers headache is less and at the same time we can achieve an optimization in this regard. go thru the following link to explore more detail. http://developer.java.sun.com/developer/technicalArticles/ALT/RefObj/ Ahimanikya Satapathy http://www.ammu.org/kuku

Reply 1

Asha · 2001-02-14 10:52:09

Where you can possibly use Reference Objects? The best place is "caching or Object pooling". Let me share one of the place i used.In my project I need to cache processed response and give back to the same similar requests( :) the goal is to increase the performance of my project).Let us assume i am getting 5 concurrent requests and the hits to my project would be 1000 per hour. If i cache all the responses in memory then i will end up with out of memory within no time. To solve this problem i wrapped the Response object in reference like this SoftReference ref = new SoftReference(response)); cache(ref); This way I am instructing the GC that it can recollect the SoftReferences when it finds shortage of memory. I only thing is your program should awrae of this cocept. How i did that ?mmm If the process do not find the response in cache then i provided alternative way to get the response.It could be processing the real work flow or some other way. Enough said . Asha Balasubramanyan http://www.ammu.org

Source notes

MyCommunity/nandighosha.org.zip!/forum/tools/snitz_forums_2000.mdb
Table: FORUM_TOPICS + FORUM_REPLY · record IDs: 13, 1