• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Rob Spoor
  • Junilu Lacar
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Carey Brown
Bartenders:

another garbage collection question

 
Ranch Hand
Posts: 225
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

output:

here it is printing yx.i did not understand why it is printing x here because when system.gc() is called only at that time finalize() method is called and hence name contains y so y should be printed what is happening here??
 
Ranch Hand
Posts: 1274
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Howdy,

there are two local objects in method m. When the method is done, both are eligible for GC, and the output just shows that.


Yours,
Bu.
 
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
why it is printing in the order yx ,not in xy?
can you explain it..
 
Ranch Hand
Posts: 424
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you add another object in method m() eg B z=new B("z"); as last.
Output will be z y x. So probably thats how GC delete objects as kind LIFO last created first destroyed, but I m not sure.
 
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can you please check the output of this code. Output is x y (Not y x)
 
Burkhard Hassel
Ranch Hand
Posts: 1274
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Seems to be system dependent?
In my windoze I get the
y
x

as Swati said.

Perhaps try this as well:
Asdf needs your B-class.
Output:
new with A
new with B
new with C
(...)
new with Y
new with Z
Z
Y
X
W
(...)
C
B
A


Yours,
Bu.
 
reply
    Bookmark Topic Watch Topic
  • New Topic