Whether it is Python or Java, as long as the VM, there are strongreference and weakreference concepts, on different VM platforms, may also produce some additional __reference concepts, such as the JVM's SoftReference, Phantomreference
Read at three and break:
1.VM management memory will probably have a reference count.
2.GC recycled memory will probably be traversed from some root object, in managed memory if some objects cannot be traversed, then these objects are garbage and should be recycled.
3. There are some additional memory usage scenarios that are not suitable for GC processing, such as various caches, so-called cache is a bunch of data, may be used at some point in time, or may never be used, so they should be valid for a certain period of time, expire and throw away. If a GC is used to process the data into a data collection object (such as LinkedList), the data in LinkedList is never recycled as long as the LinkedList is referenced.
Strongreference and WeakReference
1.StrongReference is an ordinary object reference, like Object Obj=new object (), and this obj is Strongreference, an object that belongs to a regular object in a VM and is very common.
2.SoftReference is a relatively strong reference, the memory management in the JVM is more complex, the reference is divided into different types, in different memory usage situation, with different strategies, softreference this reference general situation is not to reclaim the referenced object, But in low memory (how much memory is used is not enough memory?) This value can be configured? ), the object is reclaimed when an Oom exception is thrown. Use SoftReference to do cache back better, the data will be put in memory as far as possible, know that reached a threshold, only to start cleaning up the softreference data.
A 3.WeakReference object is a object that can get to the referenced object, but the object's life cycle is not controlled by this reference, that is, the reference does not cause an increase in the reference count, nor does it cause the traversal of the GC traversal to arrive at the referenced So the referenced object can be recycled by GC at any time.
Strongreference, WeakReference, SoftReference in Java