I thought Object finalize() is always called before the object is retired. In this test, I observed that when object is added to a collection and collection is cleared, the finalize is not called on the object. It is definitely called on the list. Note, I turned escape analysis off -XX:-DoEscapeAnalysis to prevent optimization. Could somebody explain to me, please?
List<MyClass> list=new ArrayList<>();
MyClass c=new MyClass();
listM.add(c);
list.clear();
list=null;