bairava surya wrote:After k=null three objects are eligible for garabage collection as each object has Short(wrapper class) x ,k,and Short in k object also eliglible.
Henry Wong wrote: Remember that autoboxing shorts does go through a cache.
Guillermo Ishi wrote:
Henry Wong wrote: Remember that autoboxing shorts does go through a cache.
What does that mean?
Roel De Nijs wrote:This caching mechanism is only guaranteed for the following values:
Boolean Byte Character from \u0000 to \u007f (7f is 127 in decimal) Short and Integer from -128 to 127 (inclusive)
Guillermo Ishi wrote:I think I remember this now. So what's being said is that being eligible to be cached keeps an Object from being made eligible for garbage collection?
Roel De Nijs wrote:
Yes, because the cache will always keep a reference to the object (which is by the way only created just once, when the primitive wrapper class is loaded). This of course only applies if you use the autoboxing feature or the valueOf method with the primitive parameter, in all other scenarios the object is not cached.
Guillermo Ishi wrote:It's a shorter list to remember than the types you can use.
Roel De Nijs wrote:
Guillermo Ishi wrote:I think I remember this now. So what's being said is that being eligible to be cached keeps an Object from being made eligible for garbage collection?
Yes, because the cache will always keep a reference to the object (which is by the way only created just once, when the primitive wrapper class is loaded). This of course only applies if you use the autoboxing feature or the valueOf method with the primitive parameter, in all other scenarios the object is not cached.
Cached:
Not cached:
Roel De Nijs wrote:
This caching mechanism is only guaranteed for the following values:
Boolean
Byte
Character from \u0000 to \u007f (7f is 127 in decimal)
Short and Integer from -128 to 127 (inclusive)
If the value p being boxed is an integer literal of type int between -128 and 127 inclusive (§3.10.1), or the boolean literal true or false (§3.10.3), or a character literal between '\u0000' and '\u007f' inclusive (§3.10.4), then let a and b be the results of any two boxing conversions of p. It is always the case that a == b.
If the value p being boxed is true, false, a byte, or a char in the range \u0000 to \u007f, or an int or short number between -128 and 127 (inclusive), then let r1 and r2 be the results of any two boxing conversions of p. It is always the case that r1 == r2.
Now I am super curious what sports would be like if we allowed drugs and tiny ads.
The Low Tech Laboratory Movie Kickstarter is LIVE NOW!
https://www.kickstarter.com/projects/paulwheaton/low-tech
|