Soft Reference vs Weak Reference

Report a typo

Suppose you have the following code:

public class ReferenceTypesDemo {
    public static void main(String[] args) {
        Integer num = 1995;
        SoftReference<Integer> softReference = new SoftReference<>(num);
        WeakReference<Integer> weakReference = new WeakReference<>(num);
        num = null;
    }
}

Will the object created for the num variable survive garbage collections until the application is close to running out of memory?

Select one option from the list
___

Create a free account to access the full topic