File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Regding GarbageCollection

 
Aabha Varma
Greenhorn
Posts: 22
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a program that creates 1000's of value object. All of them are in memory. When i run the program for the first time, its pretty fast and then on subsequent run its damn slow. I think its becasue GC is not happening....

ihave a method implementaion like this. could you tell me what needs to be done so that the objects are garbage collected

arrayList method(){
for(i = 0 ; i < n i++){
ValueObject v = new ValueObject();
arrayList.add(v) ;
}
return arrayList;
}

Now my question lies.. if after addding to arrayList can i make the valueobject v to null ??
can you direct me to some good implementation of effective garbage collection.
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13047
6
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Java already has a highly effective and efficient GC mechanism. Not surprising as it has been refined over 10 years.
It looks like you have the common problem of objects not being GCed because somewhere there is a collection with a reference. Since the ValueObject v reference is local to the method nothing you can do to it will help.
Bill
 
Bhanu
Ranch Hand
Posts: 48
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't think you need to worry about this logic. Insted I suggest you to optimize other parameters in the system, like the min heap size, connection pool size,Number of threads, instances of Servelts/EJB in pools etc...

After ensuring that they are all optimized and still the problem is not solved them that's the time to dig into the application using application time stamps or using some profiler to tracce out sticky objects & time consuming operations (wait for connections/DB call.Queue operations etc).
 
Ilja Preuss
author
Sheriff
Posts: 14112
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Aabha Varma:

Now my question lies.. if after addding to arrayList can i make the valueobject v to null ??


That wouldn't change anything. valueobject is just a reference to the object you also put into the list, so even if you set valueobject to null, the object will still be referenced by the list (fortunately). So no object becomes eligible for gc'ing by doing so. Additionally, the variable is set to reference to a new object in the next iteration of the loop anyway, which would have the same effect (no longer referencing the old object).
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic