看板 java 關於我們 聯絡資訊
※ 引述《ryan11 (我叫雷恩)》之銘言: : 1.我這個new是不是在每次loop中都會產生一個物件不會消失 : 會愈來愈多? : public static void main(String[] args){ : while(doesContinue){ : ... : Document doc = builder.parse(new File(xmlFile)); : ... : } : } 除非 builder 會暗地裡存著 doc 或 input file 的 reference, 否則每次 iteration 後 doc 及new 的 File 都會 eligble for GC : 2.這樣是否每次參考(theXMLFile)都被指派到新的物件上 : 而上一個loop所指派的物件就回收了, 所以不會產生太多物件 : public static void main(String[] args){ : while(doesContinue){ : ... : File theXMLFile = new File(xmlFile); : Document doc = builder.parse(theXMLFile); : ... : } : } 和上面沒有分別 : 觀念不是很好 : 請各位指點迷津 : 先謝謝了m(_ _)m Alien -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 219.77.1.206