2013年9月10日星期二

system.gc () method is used

Frequent in the program will instead lead to manually invoke the memory usage becomes large ? Causing the system to crash ?
such as a video loop, after each player once manually call system.gc (), and then during the new play, this will be the program affect you ? Who can help out ~
------ Solution ----------------------------------- ---------
Sysytem.gc (); just tell JVM garbage collection , but as for whether the JVM is no way to recover control . So you call the system without calling gc is not much affected.
------ Solution ---------------------------------------- ----
Sysytem.gc (); this simply tells the JVM garbage collection , but the JVM exactly when recovery is beyond the control of the programmer .
------ Solution ---------------------------------------- ----
I have seen one o'clock , jvm aspects of the book .

I guess might be the case.

There are many factors that can lead to jvm garbage collection.

However, two types of factors
One is triggered .

This is like you new new object , jvm found eden area ( you can be understood as a heap block area ) space is insufficient.

This time , jvm will conduct a minorGC ( you can be understood as a garbage collector ) .

One is unchecked .

such as your virtual machine parameters

when the old age of ( you can be understood as a heap block area ) in memory usage reaches 68 % of the time once majorGC ( you can be understood as a garbage collector ) .


For the trigger type, is forced gc 's .
As for the inspection type , the equivalent of a thread on the implementation of a program and periodically checks to see or need gc.


The System.gc (). Is recommended to check the virtual machine or need gc ( which is above that thread , every once in a while that program execution ) .


That would have been looking after 30s or need gc, and let him see you at this moment or need gc.


This is a personal guess , is not necessarily right.
------ For reference only -------------------------------------- -
have it, on such a system, you use the map after landing to save some temporary data you need , when exit must system.gc () be destroyed , of course, if you do not map a long time inside the key-value pairs can be without system.gc () a , jvm will be automatically cleared .
------ For reference only -------------------------------------- -
in other words, the program really frequent calls GC, but the JVM does not reach the requirements, but also not to perform, although the manual requires execution, but within the system or to the decision by the JVM are you ?
------ For reference only -------------------------------------- -
Well yes . JVM garbage recycling determine whether it should conduct its internal garbage collection . Without external domination
------ For reference only --------------------------------- ------
being the case , why some programs will still manually add a GC ?
------ For reference only -------------------------------------- -
this as you eat at the hotel , you spot a good dish , vegetables on the order , you tune system.gc (), chef anxious to see you when you put reminder of the teams , so maybe look CPU has no scheduled time for you.
------ For reference only -------------------------------------- -


Good question .
------ For reference only -------------------------------------- -
that is to say , manually call system.gc () still works. So if frequent calls, such as one minute call once, when a thread is executed once, called once , will lead to memory usage actually increased ? We reply to so much, I still do not understand whether it will affect memory ? Would not result in a system crash ?
------ For reference only -------------------------------------- -
will affect it. Think about it , has been hurried jvm things , they might it busy and it is the same resources may be consumed memory
------ For reference only ---------- -----------------------------
done a test , not necessarily accurate, relatively high in a concurrent program , each end of the thread are calling about System.gc (), the result of memory down, the original rise to about 300M JVM to be cleaned up , and now will stabilize at about 30M , but the CPU by a 1.5 percent increase from the original to about 6% , tracking a little thread , found that there is a lot of thread stack trace frequent start , so personal feeling frequent calls System.gc () there is a certain consumption of resources .
------ For reference only -------------------------------------- -
ah , ls say good ~
------ For reference only -------------------------- -------------
static int i = 1;
public RubbishRelease () {
System.out.println (i + +);
}

public void finalize () {
System.out.println ("finalize ...");
}

public static void main (String [] args) {
for (int i = 0; i <100000; i + +) {
new RubbishRelease ();
new RubbishRelease ();
new RubbishRelease ();
System.gc ();
}
System.out.println ("over!");
}

Try this - relatively lower rate, very obvious, so gc is not easily applicable to tick ~
------ For reference only --------------- ------------------------
system.gc () only recommended jvm recycling garbage , but the decision is still in the JVM hands by her decision whether now recycle rubbish.

没有评论:

发表评论