N
Naveen Kumar
I am confused by someone over object creation in java.. Here is a
sample question..
class Card {
Short story=5;
Card go(Card c)
{
c=null;
return c;
}
public static void main(String[] args)
{
Card c1=new Card();
Card c2=new Card();
Card c3=c1.go(c2);
c1=null;
//do stuff;
}
when //do stuff is reached How many Objects are eligible for garbage
Collection ?
Does c3 occupies memory and is eligible for garbage collection..
When we say
Card c3 = null;
Isnt memory allocated to this reference for storing valid object.. and
is now available for gc .. ???
Wht happens in case when i say Card c3 = null ?? Isnt heap and stack
space utilized ?
sample question..
class Card {
Short story=5;
Card go(Card c)
{
c=null;
return c;
}
public static void main(String[] args)
{
Card c1=new Card();
Card c2=new Card();
Card c3=c1.go(c2);
c1=null;
//do stuff;
}
when //do stuff is reached How many Objects are eligible for garbage
Collection ?
Does c3 occupies memory and is eligible for garbage collection..
When we say
Card c3 = null;
Isnt memory allocated to this reference for storing valid object.. and
is now available for gc .. ???
Wht happens in case when i say Card c3 = null ?? Isnt heap and stack
space utilized ?