Skip to content

Commit

Permalink
Declare factory methods with %newobject
Browse files Browse the repository at this point in the history
Add the %newobject SWIG declaration to the factory methods createLattice()
and createTagger() of the class MeCab::Model. This makes it clear that the
caller takes on ownership of the pointer returned by these factory methods.

Without this declaration, calls in e.g. Java to Model.createLattice() and
Model.createTagger() will leak memory, as the generatedd Java Lattice and
Tagger proxy classes do not know that they have ownership of the underlying
C++ pointers. As a result, instances of the proxy classes fail to delete
the underlying C++ objects, leading to native (off-JVM-heap) memory leaks
that are difficult to debug.
  • Loading branch information
mjansche committed Aug 12, 2020
1 parent cd8048e commit 75fc31b
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions mecab/swig/MeCab.i
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
%}

%newobject surface;
%newobject MeCab::Model::createLattice;
%newobject MeCab::Model::createTagger;

%exception {
try { $action }
Expand Down

0 comments on commit 75fc31b

Please sign in to comment.