diff --git a/SWIG/Examples/java/callback/index.html b/SWIG/Examples/java/callback/index.html index 1d890f888..c36c63d6c 100644 --- a/SWIG/Examples/java/callback/index.html +++ b/SWIG/Examples/java/callback/index.html @@ -16,13 +16,6 @@

This example illustrates how to use directors to implement C++ callbacks in Java.

-

-Please note that unlike Python, Java does not have an equivalent concept of -weak references, so the program has to manually clean up after objects. The -implication of this is that the Caller class cannot claim -ownership of the Callback object in Caller.setCallback() -and delete it. -


diff --git a/SWIG/Examples/java/callback/main.java b/SWIG/Examples/java/callback/main.java index 9e7af267e..4800f8cc9 100644 --- a/SWIG/Examples/java/callback/main.java +++ b/SWIG/Examples/java/callback/main.java @@ -21,14 +21,6 @@ public class main caller.call(); caller.delCallback(); - // Unlike Python, Java does not automatically support "weak" - // references (*), so we're left with managing the memory. - // - // (*) Yes, there is a WeakReference class, but it doesn't - // work exactly the way the Python weak reference works. - - callback.delete(); - callback = new JavaCallback(); System.out.println(); @@ -39,6 +31,9 @@ public class main caller.call(); caller.delCallback(); + // Test that a double delete does not occur as the object has already been deleted from the C++ layer. + // Note that the garbage collector can also call the delete() method via the finalizer (callback.finalize()) + // at any point after here. callback.delete(); System.out.println();