[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 189
  • Last Modified:

java garbage collect

I use jvc(just-in-time) compile my program, and use jview to run it.
can I forbid garbage collect to happen until program run out of memory.
I put one System.gc in different place in my program, why does it cost very different runing time in the same program(9 class).
 
0
yijun
Asked:
yijun
1 Solution
 
russgoldCommented:
You cannot generally control garbage collection in a system with automatic garbage collection (AG), such as Java.  This is one reason many people don't like AG in real-time systems.  The behavior is simply not predictable.

The normal behavior for most Java VM's is to delay all gc activity until it runs out of memory - or Runtime.gc() is called.
You can take advantage of this fact by adding calls to Runtime.gc() at various non-time-critical points in your system to ensure that a large backlog of unreferenced objects never develops.  Your behavior will still not be entirely predictable, but it should never get to be a problem.
0
 
yijunAuthor Commented:
Hi, thanks!
But how to delay gc happen until using out of memory?
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now