Originally posted by vishnu priya parimi:
2. A program can suggest that garbage collection be perfomed but not force it.
2. use the Runtime.ge() method to force garbage collection.
...you can suggest or encourage the JVM to perform garbage collection but you can not force it.
Let me re-state that point, you cannot force garbage collection, just suggest it.
...
You can suggest garbage collection with System.gc(), but this does not guarantee when it will happen
Answer 55)
Objective 3.1)
Back to Question 55)
1) You cannot be certain when garbage collection will run
Although there is a Runtime.gc(), this only suggests that the Java Virtual Machine does its garbage collection. You can never be certain when the garbage collector will run. Roberts and Heller is more specific abou this than Boone. This uncertainty can cause consternation for C++ programmers who wish to run finalize methods with the same intent as they use destructor methods.
Runs the garbage collector.
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.
Runs the garbage collector.
Calling the gc 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 Java Virtual Machine has made a best effort to reclaim space from all discarded objects.
42
When control returns from the method call, the Java Virtual Machine has made a best effort to reclaim space from all discarded objects
Ask a Meaningful Question and HowToAskQuestionsOnJavaRanch
Getting someone to think and try something out is much more useful than just telling them the answer.
is it correct in one of the mock exams the first one is correct or
-->Ensure that all variables you require to be garbage collected are set to null.
Impossible is I M Possible
Politics n. Poly "many" + ticks "blood sucking insects". Tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
|