Maybe you misunderstand what is myObject.In java, everything is an object which you should new it if you want it (except those of primitive type, such as integer...).In your code, myObject and anObject are not string object but are two string object reference pointing to a same string object you created in you AllocateObject() method.So, when you quit AllocateObject, the released is not an string object created from heap, but a reference variable allocated from stack.Since your anObject reference keep reference to this string object, It can not be collected by garbage collector untill anObject variable is released.Furthmore, It doesn't mean this string object has been collected if nobody reference it. The collection depends on the resource usage. and garbage collector do it in the lazy collection way.
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货