• Post Reply Bookmark Topic Watch Topic
  • New Topic

Garbage collection problems in java?

 
Bryan Welch
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I've been hearing at work that the garbage collection in java isn't that good, and that for large applications it can be a problem.
Is this true? Could someone comment more on this? I don't know enough to know if the problems we're having are due to poor coding technique or bugs within the jdk.
thanks,
------------------
----
Bryan Welch
bwelch@abcv.com
 
paul wheaton
Trailboss
Posts: 22064
Firefox Browser IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It depends on the VM. It can certainly be tricky if you are running a memory intensive program with limited memory and the application needs to have real time response. However, I have not recently experienced any problems with the garbage collection - so maybe these problems are gone now.
Anybody else?
 
Jim Thomas
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The garbage collection implementation for JDK1.2 has been touted as a vast improvement over JDK1.1 Its supposed to be even better with JavaSoft's HotSpot VM.
The only problem I have encountered has been when garbage collection is invoked on memory that has been swapped to disk. It can be very slow. I would recommend that you make sure mission critical apps (especially J2EE application servers) are never subject to being swapped to disk.
 
Jeroen Wenting
Ranch Hand
Posts: 5093
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
garbage collection has two (potential) problems:
1) performance
2) memory use
1) is caused by the running of the garbage collector. In an application that causes a lot of objects to go out of scope, garbage collection can eat a lot of CPU cycles, slowing the application down. As said before, this gets worse if part of the application is swapped out to disc, as then the garbage collector calls swapped-out objects, which causes delays.
2) The garbage collector itself takes up some memory (of course), but if you use many objects, these all stay in memory even if no longer in use until such time that the garbage collector gets around to deleting them. This can be a long time (remember that the garbage collector is guaranteed to run only on termination of the JVM...).
 
Praveen Kannan
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
One thing i don't like about the JVM specs is the fact that the call to System.gc() only recommends the VM to run the gc and not actually run it. I was wondering if there is anyway you could change the priority of the gc thread, so that, once in a while we can make [i]sure[i] that gc runs to clean up the resources. Or is there any way that we could halt our threads and invoke the gc thread??
 
Manoj Prithiani
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Garbage Collection is high priority in JDK 1.3.Just Nullify the variables to be Garbage Collected and call System.gc(). Or else if it is some Streams closing them would ensure they will be Garbage Collected
 
Jack Shirazi
Author
Ranch Hand
Posts: 96
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Certainly you're all right. Firstly make sure you use the latest JVM available, the garbage collection algorithms improve each time. Secondly address the memory you're using. For memory intensive apps, you can use a huge variety of techniques to reduce memory requirements.
O'Reilly have put the "Object Creation" chapter of my book online (follow the link from the book page), and you can also check out many other tips from the summary lists at my site. The techniques covered can improve application performance considerably, not just because they reduce the impact of garbage collection, but also because they reduce object creation. Object creation overheads are significant, and are not really improved by JITs or HotSpot.
As far as the collector thread is concerned, there is no standard way of altering its priority. About the best you could do is synchronize a pause (wait()) across your own threads, calling gc() from one thread and releasing all threads on return. At least this would make sure that the collector thread was the only non-idle thread. I'm not sure of the benefit of this strategy.
 
David Celano
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I've heard that at some point in the future it may be possible to select from a number of different GC's to find one that's best suited to your needs. Does anyone know if this is likely to happen soon?
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!