1

Possible Duplicate:
Java garbage collector - When does it collect?

When people say that garbage collector in Java is slowing the whole application down, what do they really mean by it? Isn't garbage collector only gets triggered whenever an Object is relieved? Please help me understand. Thank's!

1
  • relieved? Sorry, I can't figure it out.
    – bmargulies
    May 21, 2011 at 1:31

4 Answers 4

0

Take a look at http://developers.sun.com/mobility/midp/articles/garbage/

As Java technology becomes more and more pervasive in the telecommunications (telco) industry, understanding the behavior of the garbage collector becomes more important. Typically, telco applications are near-real-time applications. Delays measured in milliseconds are not usually a problem, but delays of hundreds of milliseconds, let alone seconds, can spell trouble for applications of this kind. Quite simply, sub-optimal performance translates directly into loss of revenue.

Basically, if the garbage collector compacts a small heap then the delay is short, but if you have been generating a lot of garbage, and have a large reachable object graph, you can see large delays. New garbage collection algorithms (generational / incremental GC) have mitigated this to some degree but tuning GC is still somewhat a black art.

2
  • @Stephen C. I was assuming that the size of the heap is proportional to the number of non-garbage objects. The cost of a single GC pass is indeed proportional to the number of those objects in a mark&sweep collector without ephemeron tables, but the number of GC passes performed is proportional to the combined size occupied by generated garbage objects. Will edit to use the term "incremental" instead of "concurrent" GC. May 21, 2011 at 2:21
  • @Stephen C. I edited a bit more. I think you were right that my language was confusing. May 21, 2011 at 2:23
0

Garbage collection doesn't happen in specific moments. It happens when the VM decides to do so (probably when it runs out of memory).

Garbage collection is another work that your process should do, so in the total time, your program is slower. BUT during the execution the lag felt (by the user) is minimal.

0

When the Java Virtual Machine runs out of memory (or decides to start garbage collection for some other reason), the garbage collector will determine if there are any objects which are no longer in use. This is expensive (especially if you have a lot of objects), and can occur at unpredictable times.

In contrast, languages like C which do not have garbage collectors allow the programming a finer level of control. This can avoid expensive and unpredictable garbage collection runs, or at least ensure that they don't occur at inopportune moments.

0

In Java, object life is managed automatically. The Java garbage collector will perform mark and sweep algorithm (O(N) algorithm) to walk the object graph and clean up objects that are not being referenced. Users do not have a reliable way to trigger the garbage collection (user can call System.gc(), but it's not guaranteed to run immediately). When garbage collection will happen pretty much relies on the JVM implementation.

So, back to your question, when people say garbage collection is slowing their application down, it means the mark and sweep algorithm is taking away some of their machine's silicon time.

In iOS world, what you said is right, object gets garbage collected when they're relieved. Relieved here means the reference count of the object becomes 0, and the programmer is responsible for increasing or decreasing the reference count. In this case, the run time of garbage collection is O(1).

Not the answer you're looking for? Browse other questions tagged or ask your own question.