Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Actually allows the GC to reclaim tasks (fix #18874)
[simgrid.git] / src / bindings / java / org / simgrid / msg / Task.java
index 95893ec..16e54ef 100644 (file)
@@ -161,17 +161,19 @@ public class Task {
        /** Cancels a task. */ 
        public native void cancel();
 
-       /** Deletes a task.
-        *
-        * @exception                   NativeException if the destruction failed.
-        */ 
-       protected void finalize() throws NativeException {
-               destroy();
+       /** Deletes a task once the garbage collector reclaims it */
+       @Override
+       protected void finalize() {
+               try {
+                       // Exceptions in finalizers lead to bad situations:
+                       // http://stackoverflow.com/questions/7644556/troubleshooting-a-java-memory-leak-finalization
+                       doFinalize();
+                       bind=0; // to avoid segfaults if the impossible happens yet again making this task surviving its finalize()
+               } catch (Exception e) {
+                       e.printStackTrace();
+               }
        }
-       /**
-        * The natively implemented method to destroy a MSG task.
-        */
-       protected native void destroy();
+       protected native void doFinalize();
        /* *                       * *
         * * Communication-related * *
         * *                       * */