Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

garbage collection

 
Suhita Reddy
Ranch Hand
Posts: 60
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

after line 6 runs,how many objects r eligible for garbage collection?
1.public class X{
2.public static void main(String args[]){
3.X x=new X();
4.X x2=m1(x);
5.X x4=new X();
6.x2=x4;
7.doComplexStuff();
8.}
9.static X m1(X mx){
10.mx=new X();
11.return mx;
12.}
13.}
 
Karol Kisielewski
Greenhorn
Posts: 8
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Suhita Reddy:
Hi all,

after line 6 runs,how many objects r eligible for garbage collection?
1.public class X{
2.public static void main(String args[]){
3.X x=new X();
4.X x2=m1(x);
5.X x4=new X();
6.x2=x4;
7.doComplexStuff();
8.}
9.static X m1(X mx){
10.mx=new X();
11.return mx;
12.}
13.}


Only one and it is object created by m1 method (line 4)
 
Barry Gaunt
Ranch Hand
Posts: 7729
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Agreed. If you assume that the System.gc() calls work as expected in the following code - you can see it happen:

 
Barry Gaunt
Ranch Hand
Posts: 7729
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Regarding the above test: run it at the command line rather than using an IDE.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic