Advertisement

[java] Efficiency & Memory

Started by March 27, 2001 06:19 PM
10 comments, last by Flanders 23 years, 10 months ago
quote:
Original post by Anonymous Poster

Garbage collection shouldn''t take _too_ long, System.gc() will return practically straight away, but it might not have done anything (it''s merely a request). So if you _know_ that you have garbage to collect you can sit in a while loop untill you have more free memory.



Er yea, System.gc() returns stright away cuss it forks a thread! You still have to account for the load caused by it, thus its aways a bad idea to gc in a loop unless you check that the last thread has been killed.
The api doc says:

When control returns from the method call, the Java Virtual Machine has made its best effort to recycle all discarded objects.

(for Runtime.gc())

I guess it probably does just fork a thread, but it might not. Kind of vague. I guess this ones JVM specific.

This topic is closed to new replies.

Advertisement