Class CardBoard {
Short story = 200;
CardBoard go(CardBoard cb){
cb = null;
return cb;
}
public static void main(String args[]){
CardBoard c1 = new CardBoard();
CardBoard c2 = new CardBoard();
CardBoard c3 = c1.go(c2);
c1 = null; // (1)
// some code
}
}
First we can go through the code,- We are creating two objects and they are referred by reference variables c1 and c2.- During the execution of thisline
CardBoard c3 = c1.go(c2);
no new objects are created in the heap.
- The memory allocated for c1 can be garbage collected after line
c1 = null;
But the total number of objects garbage collected is 2 since the CardBoard class contains one wrapper object Short.
Comments
Post a Comment