Question

How often is garbage collected in Java (on a regular PC and on an Android phone)? I tried looking it up, but did not get a number. I know it probably depends on a lot of factors, but I just want a rough idea.

Was it helpful?

Solution

The time varies depending on the memory usage. There are also major and minor collections. You can read more about it here (http://www.oracle.com/webfolder/technetwork/tutorials/obe/java/gc01/index.html)

OTHER TIPS

It might never be collected, if not necessary. Many applications don't allocate enough memory during the duration of their execution to cause a collection. And there are different types of algorithms which run in different situations, and they cause different delays. You have to monitor you memory use to measure the frequency of garbage collections for a given application running under specific conditions. You can configure the way garbage collection is executed and choose different algorithms by configuring your JVM.

There is a tool called JConsole that you can use to monitor memory allocation in real-time and it's great to discover memory leaks, but you should read a bit about how garbage collection works first, so you understand how memory is organized and how the algorithms work.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top