[Java] vtkObjectBase.Delete() corrupts vtkGlobalJavaHash
This issue was created automatically from an original Mantis Issue. Further discussion may take place here.
The Java garbage collector (called GC in this bugreport) removes weak references from vtkGlobalJavaHash.PointerToReference when it deletes unused objects. This is all good. Buf if vtkObjectBase.Delete() is called explicitly (which is recommended in Java to avoid threading issues), vtkGlobalJavaHash.PointerToReference is not updated and contains an invalid entry, old vtkId points to an object which has been deleted from native code but not yet GC'ed. If native code reuses the same address before object is GC'ed, vtkGlobalJavaHash.PointerToReference.get(vtkId) will return this object instead of null. Here is a test case to reproduce this bug, output is: Exception in thread "main" java.lang.ClassCastException: vtk.vtkQuadric cannot be cast to vtk.vtkDataArray at vtk.vtkDataArray.CreateDataArray(vtkDataArray.java:267) at BugWeakRef.main(BugWeakRef.java:21)