Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Are objects cleaned up when references to them are nulled?

Tags:

java

public class App1 
{

 public static void main(String[] args) 
 {
   Point point_1 = new Point(5,5);
   Point point_2 = new Point(7,8);
   Circle circle_1 = new Circle(point_2, 10);
   point_1 = null;
   point_2 = null;
 }
}

How many object references exist after this code has executed? Why?

like image 554
lili Avatar asked Nov 27 '25 16:11

lili


1 Answers

After this code has executed, exactly none, since it will have exited :-)

If you mean at the point just before exit, there's a reference on the stack to your circle and a reference in your circle to the second point, assuming the constructor stores it.

like image 130
paxdiablo Avatar answered Nov 29 '25 06:11

paxdiablo



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!