Topic: garbage collected

  Print this page

1.garbage collected Copy to clipboard
Posted by: hohaischooldays
Posted on: 2003-12-09 16:49

QUESTION NO: 6
Which statement is true?
A. Memory is reclaimed by calling Runtime.gc().
B. Objects are not collected if they are accessible from live threads.
C. Objects that have finalize() methods are never garbage collected.
D. Objects that have finalize() methods always have their finalize() methods called before the program ends.
E. An OutOfMemory error is only thrown if a single block of memory cannot be found that is large enough for a particular requirement.

Answer: B //OutOfMemory //finalize()

why A is wrong?

2.Re:garbage collected [Re: hohaischooldays] Copy to clipboard
Posted by: looluo
Posted on: 2003-12-10 17:34

FROM Java api docs

public void gc()

Runs the garbage collector. Calling this method suggests that the Java virtual machine expend effort toward recycling unused objects in order to make the memory they currently occupy available for quick reuse. When control returns from the method call, the virtual machine has made its best effort to recycle all discarded objects.
The name gc stands for "garbage collector". The virtual machine performs this recycling process automatically as needed, in a separate thread, even if the gc method is not invoked explicitly.

The method System.gc() is the conventional and convenient means of invoking this method.

3.Re:garbage collected [Re: hohaischooldays] Copy to clipboard
Posted by: dorrenchen
Posted on: 2003-12-10 23:09

ideally it's not necessary to call Runtime.gc() in your code, since JVM is suppose to do it automatically. When you do call "Runtime.gc()" explicitly in the code, you are just merely reminding JVM it's time to clean the house. JVM will do it soon or later, but it's not obligated to do it immediately, so you do not know exactly when the garbage objects will be collected.

4.Re:garbage collected [Re: hohaischooldays] Copy to clipboard
Posted by: hohaischooldays
Posted on: 2003-12-17 14:18

thanks very much!

5.Re:garbage collected [Re: hohaischooldays] Copy to clipboard
Posted by: dingligang
Posted on: 2003-12-19 19:51

学习Smile
java虚拟机不保证显示调用finalize() 方法的时候就立即回收资源


   Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent
Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1
客服电话 18559299278    客服信箱 714923@qq.com    客服QQ 714923