Skip to content

fix(lightgbm): ensuring c++ resources created in swig are released after training#150

Merged
artpdr merged 2 commits into
feedzai:masterfrom
jpleitao:ft-jl-lightgbm-sample-weight
May 20, 2026
Merged

fix(lightgbm): ensuring c++ resources created in swig are released after training#150
artpdr merged 2 commits into
feedzai:masterfrom
jpleitao:ft-jl-lightgbm-sample-weight

Conversation

@jpleitao
Copy link
Copy Markdown
Contributor

Summary

This PR addresses a memory leak introduced in #147, by not ensuring the release of all allocated SWIG resources, in particular when training crashes (e.g., when an IllegalArgumentException is thrown due to negative sample weights provided). To ensure allocated resources are always released, a try-with-resources is used for the training logic, ensuring the call to .close() method for the two resources created - swigTrainData and swigTrainBooster -, regardless if the training is successful or not

…ter training, even if an exception is thrown
@jpleitao jpleitao requested a review from AlbertoEAF May 20, 2026 08:43
Copy link
Copy Markdown
Contributor

@AlbertoEAF AlbertoEAF left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great! Let's get this memleak fix merged in all pulses!

@codecov
Copy link
Copy Markdown

codecov Bot commented May 20, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 81.37%. Comparing base (fe58343) to head (dc8db8f).
⚠️ Report is 4 commits behind head on master.

Additional details and impacted files
@@             Coverage Diff              @@
##             master     #150      +/-   ##
============================================
+ Coverage     80.37%   81.37%   +1.00%     
- Complexity      469      519      +50     
============================================
  Files            48       52       +4     
  Lines          1620     1756     +136     
  Branches        157      177      +20     
============================================
+ Hits           1302     1429     +127     
- Misses          231      234       +3     
- Partials         87       93       +6     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@artpdr artpdr merged commit d91f0c2 into feedzai:master May 20, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants