这样写JAVA 没有被变量名引用的堆数据会被释放掉吗?JAVA数据结构

JAVA写一个链式数据结构

class stu{
    int age;
    stu pn;
    
    public stu(int age){
        this.age=age;
        pn=null;
      
    }
}

  

public class shuju{
    public static void main(String args[]) {
        
        stu first,temp,last;


         first=new stu(0);
         last=first;


                for(int counter=0;counter<5;counter++) {
                     
                         //循环5次生成了5个对象


                        temp=new stu(num); 
                         last.pn=temp;
                         last=last.pn;
                    
                          
                }
                
            } 

现在first变量名引用着根对象空间

last和temp引用着最后一个生成的对象空间

中间的没有被变量名引用的对象空间会被自动释放掉吗?

当然会