#1251 Java Directors: Do not use weak references directly

java (79)

Using Directors on Android will eventually lead to a crash, with no trace output, either during GC or if the user calls delete(). This bug was reported earlier:


But it is not fixed as of SWIG 2.0.6 and I'm assuming it is not fixed today because the thread on the mailing list died.

All you have to do to reproduce is make a director-based object and then call .delete() on it, something like:

%feature("director") Foo;
%inline %{ struct Foo {
virtual void f() {}
}; %}
// Java
class Foo2 extends Foo {}
public void Repro() { new Foo2().delete(); }

The proposed patch works, and peek() should either be removed or have a warning comment placed on it, because using a weak global reference directly is not allowed on Android.


  • William Fulton

    William Fulton - 2012-09-13
    • status: open --> closed-fixed
  • William Fulton

    William Fulton - 2012-09-13

    Thanks for the example and posting the patch. I've added an Android example based on this and have committed the patch for swig-2.0.9.


Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:

No, thanks