- // Check inside the map if the object is already there
- WeakReference<vtkObjectBase> value = objectMap.get(vtkId);
- vtkObjectBase resultObject = (value == null) ? null : value.get();
-
- // If not, we have to do something
- if (value == null || resultObject == null) {
- try {
- // Make sure no concurrency could happen inside that
- this.lock.lock();
-
- // Now that we have the lock make sure someone else didn't
- // create the object in between, if so just return the created
- // instance
- value = objectMap.get(vtkId);
- resultObject = (value == null) ? null : value.get();
- if (resultObject != null) {
- return resultObject;
- }
-
- // We need to do the work of the gc
- if (value != null && resultObject == null) {
- this.unRegisterJavaObject(vtkId);
- }
-
- // No-one did create it, so let's do it
- if (resultObject == null) {
- try {
- String className = vtkObjectBase.VTKGetClassNameFromReference(vtkId.longValue());
- Class c = Class.forName("vtk." + className);
- Constructor cons = c.getConstructor(new Class[] { long.class });
- resultObject = (vtkObjectBase) cons.newInstance(new Object[] { vtkId });
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- } finally {
- this.lock.unlock();
- }
+ // We need to do the work of the gc
+ if (value != null && resultObject == null) {
+ this.unRegisterJavaObject(vtkId);