• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

WeakReference Reclaiming Large Object

 
Ranch Hand
Posts: 208
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I try to test WeakReference as below. If I don't print out a reference to a large object (last line), GC reclaimed large object. On the other hand, if I print large object (last line), GC could not reclaim large object.
Why?



weak Ref [Ljava.lang.Double;@197a37c
weak Ref [Ljava.lang.Double;@197a37c
weak Ref null
weak Ref null
weak Ref null


#### now if I comment out the last line to print "large ref", GC did not reclaim large object. Why?

weak Ref [Ljava.lang.Double;@197a37c
weak Ref [Ljava.lang.Double;@197a37c
weak Ref [Ljava.lang.Double;@197a37c
weak Ref [Ljava.lang.Double;@197a37c
weak Ref [Ljava.lang.Double;@197a37c
large ref [Ljava.lang.Double;@197a37c
 
author
Posts: 23956
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Based on a quick look at the code, the GC should not be able to collect the object referred to by the weak reference -- as you have a strong reference pointing to the same object.

Henry
 
vu lee
Ranch Hand
Posts: 208
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That what I thought. Initially, I set large = null, just before the while loop. After running a few tests, I realized that this statement made no difference.
 
reply
    Bookmark Topic Watch Topic
  • New Topic