You create the stringbuffer object just to use , why care the init size 這樣不是更好嗎?可以節(jié)省內(nèi)存啊?為什么別人不這么產(chǎn)生對象呢
Object is created and referenced by the variable . at that point the 該方法執(zhí)行一次,一個新的stringbuffer將被創(chuàng)建并且被sb變量引用。
Object , and now it can be garbage collected . this elimination of the reference is equivalent to nulling the 于是不再有對該stringbuffer對象的引用,現(xiàn)在它就可以被當(dāng)作垃圾收集了。
Object created in the first line . as long as the method is executing , the reference to the 當(dāng)該方法執(zhí)行時,運(yùn)行時棧保留了一個對stringbuffer對象的引用,這個對象是在程序的第一行產(chǎn)生的。
Is being held onto by the application for much longer than it needs to be - possibly forever if no one ever calls 也就是說,這個死亡的stringbuffer對象被程序保留的時間比它實(shí)際需要保留的時間長得多如果再也沒有對該scopingexample方法的調(diào)用,它將會永遠(yuǎn)保留下去。