+1 vote
in JAVA by
How can an object be unreferenced?

1 Answer

0 votes
by
There are many ways:

By nulling the reference

By assigning a reference to another

By anonymous object etc.

Java Garbage Collection Scenario

1) By nulling a reference:

Employee e=new Employee();  

e=null;  

2) By assigning a reference to another:

Employee e1=new Employee();  

Employee e2=new Employee();  

e1=e2;//now the first object referred by e1 is available for garbage collection  

3) By anonymous object:

new Employee();

Related questions

0 votes
asked Jan 11, 2021 in Python by SakshiSharma
0 votes
asked Apr 9, 2021 in JAVA by Robindeniel
...