Skip to content

Memory leak in SWIG java wrappers #6922

@s-rwe

Description

@s-rwe

Description

We noticed an apparent memory leak when calling the SWIG Java wrappers, in our case namely for (repeated) calls to LGBM_BoosterSaveModelToStringSWIG. Doing so repeatedly keeps piling up more and more leaked memory, for each returned model string.

It seems that a patch with corresponding %newobject definitions in the swig interface (swig/lightgbmlib.i) fixes the issue and takes care of the necessary cleanup in the swig-generated code:

%newobject LGBM_BoosterSaveModelToStringSWIG;
%newobject LGBM_BoosterDumpModelSWIG;

Environment info

We are using the wrappers via https://github.com/metarank/lightgbm4j, which includes (in its latest version) LightGBM of v4.4.0. Using the latest release v4.6.0 instead doesn't change things, but the above %newobject declarations resolved the memory issues we're seeing.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions