Java常见的引用类型
1、强引用:普通的变量引用,Student sut=new Student();
2、软引用:堆内对象若未被引用,GC不会立刻删除,而是在堆内存空间不足时才会进行删除。
3、弱引用:GC触发,会立刻删除。
4、虚引用:又名幽灵引用,幻影引用。
弱引用:
Student s2 = new Student();WeakReference<Student> weakReference = new WeakReference<>(s2);System.out.println(weakReference.get());s2 = null;System.gc();System.out.println(weakReference.get());