actively prompt to reclaim memory
imagine such a scenario
you have 100m memory, and each operation requires 60MB. After each operation is completed, the system has 40m JVM that will not be actively reclaimed, but will OOM, if you apply for 60m for the second operation.
pseudo codes are as follows:
void bigmemop(){
for(int i=0; i<100; iPP){
use60M();
System.gc();
}
}
this happens when dealing with large Excel tables in a project. When memory is limited (when is it not limited?) Active control is still very important.
It obviously doesn't make sense for PS:
code to rely on Gc, because gc may do nothing. If you don't know whether to use it or not, the answer is: don't use it!
but not all jvm are smart, and not all jvm default behaviors are the same. When there is no better way to deal with memory recycling, System.gc provides you with a choice and possibility.
many items are used:
such as , eclipse-jetty ,
jmbr3d/MeshBrowser.java
roughly boils down to the following scenarios:
UPDATE2:
I used gc in my project nearly 10 years ago, using JDK 1.5. The situation is also much more complicated than the above example, so as not to mislead everyone, mark it first.
so it is rarely used. I've never used it anyway.
-disagree with the downstairs answer.
in order to confirm the correctness of my judgment, I specifically checked some data, but in the data I looked up, I did not say that "calling System.gc () can prevent OOM."
the description of System.gc () on the JDK document is:
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.
Note that you use "suggests" instead of "make".
there is also this question and answer on SO: https://stackoverflow.com/que.
Almost all of the answers inmention that System.gc () only "suggests" garbage collection, not "one must" do garbage collection.
and the answer with the highest number of votes clearly stated one sentence:
If the JVM is about to throw an OutOfMemoryError, calling System.gc () won't stop it
so, @ Yujiaao, I expect your example to do this: plus System.gc () will not OOM, the effect of OOM without adding .
Previous: Can table use flex layouts?
Next: How to use echarts, or Highcharts to make a non-overlapping bubble chart,
< H2 > the book says: during the concurrent cleanup phase, the user thread is still running, and new garbage may be generated during this period. New garbage cannot be removed this time GC, but can only be cleaned up next time. These rubbish have a profe...
for example, the member variable of a class: Object obj = new Object(); obj is an instance of an object. In a broad sense, it is stored on the "stack " and points to the memory address on the "heap ". Specifically, I have the impression that obj sho...
I want to dump all the classes loaded by the virtual machine through the ClassDump in sa-jdi.jar. ClassDump supports dump classes from jvm processes or jvm core dump. for online applications, you should not dump, pid directly if you want to get a co...