This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Minimizing Garbage Collection Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Reply locked New topic
Author

Minimizing Garbage Collection

Vivek Jain
Ranch Hand

Joined: Oct 17, 2007
Posts: 34
Hello Gurus,
I would like to know how can we minimize the garbage collection in Java. I know that garbage collection cannot be forced.

But still what could be the best practices to minimize or avoid garbage collection in Java???

Thanks!
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19655
    
  18

Originally posted by Vivek Jain:
But still what could be the best practices to minimize or avoid garbage collection in Java???

First think of yourself if you really want this. Without garbage collection, objects are never cleaned up, and the heap just fills up until it is full and the JVM throws an OutOfMemoryError.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14074
    
  16

In general, you don't need to worry about garbage collection in Java. The JVM contains very sophisticated algorithms to make garbage collection as efficient as possible, and you are probably not going to gain much by trying to optimize it.

However, if you want to know all the details, have a look at this document:
Tuning Garbage Collection with the 5.0 Java[tm] Virtual Machine


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Minimizing Garbage Collection
 
Similar Threads
Garbage Collection Question
Garbage collection
when is destroy called
garbage collection question
minimize the need of garbage collection ?