3 回答
TA贡献1777条经验 获得超3个赞
class FinalizeThis { protected void finalize() { System.out.println("finalized!"); } void loop() { System.out.println("loop() called"); for (int i = 0; i < 1_000_000_000; i++) { if (i % 1_000_000 == 0) System.gc(); } System.out.println("loop() returns"); } public static void main(String[] args) { new FinalizeThis().loop(); }}
loop()
FinalizeThis
loop() called finalized!loop() returns
MimeBodyPart
m_
更新
public static void main(String[] args) { FinalizeThis finalizeThis = new FinalizeThis(); finalizeThis.loop(); }
public static void main(String[] args) { FinalizeThis finalizeThis = new FinalizeThis(); for (int i = 0; i < 1_000_000; i++) Thread.yield(); finalizeThis.loop(); }
main()
main()
finalizeThis
loop()
-Xcomp
TA贡献1801条经验 获得超8个赞
super.finalize()
HTTPMessage
Object
finalize()
finalize()
添加回答
举报