2013年10月11日星期五

Ask: a global object , new many times, is not the cause of the memory has been increased ?

Class defines a global object , in many new, but did not assign null, is not it will cause a memory has been increased ?
------ Solution ---------------------------------------- ----
bar code on the landlord , depending on the context to know whether there is leakage situation.
Generally speaking, if a variable is not thread call stack and static references, the garbage collection period will be released .
------ Solution ---------------------------------------- ----
not , the global object will only save the last one new reference to an object , the object heap is the last one new object in front of new objects will be garbage collected for .
------ Solution ---------------------------------------- ----
global variable will point to the heap last new objects. The new front is recovered. Objects in the heap as long as no reference to it , it can be recycled.
------ Solution ---------------------------------------- ----
into local variables were re- assigned to the new global.
------ For reference only -------------------------------------- -
before the new assignment null is not to secure ?

没有评论:

发表评论