In Java, there is a method called System.gc()
, which calls the garbage collector (or rather, "suggests" to the JVM to run the GC).
Are there valid reasons to call this method? I'm thinking that it would be evident of bad software design.
Software Engineering Stack Exchange is a question and answer site for professionals, academics, and students working within the systems development life cycle. It only takes a minute to sign up.
Sign up to join this communityIn Java, there is a method called System.gc()
, which calls the garbage collector (or rather, "suggests" to the JVM to run the GC).
Are there valid reasons to call this method? I'm thinking that it would be evident of bad software design.
How about a benchmarking suite? Rather than letting the GC run at any random time, you might want to make it run between sets of tests, to (possibly) create more consistent conditions for each set.
System.gc()
each time? I understand it's somewhat random in both situations but then I'd rather have it be random in the way I expect: after many tests there will be GC's; this could let me take that into account.
– Jeroen Vannevel
Aug 1 '14 at 21:14
What about a game where you want to control gc pauses. You could then call gc right before a level starts after assets are loaded.
In general, there isn't a good reason to call System.gc(). Especially since the system might ignore it. But here are some plausible reasons.