Skip to content

Commit 0f332a2

Browse files
committed
Fixed memory leak with cv method
1 parent 57f5235 commit 0f332a2

File tree

3 files changed

+9
-5
lines changed

3 files changed

+9
-5
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 0.4.4 (unreleased)
2+
3+
- Fixed memory leak with `cv` method
4+
15
## 0.4.3 (2025-06-26)
26

37
- Added ARM shared library for Linux

lib/lightgbm/booster.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ class Booster
55
attr_accessor :best_iteration, :train_data_name, :params
66

77
def initialize(params: nil, train_set: nil, model_file: nil, model_str: nil)
8+
@refs = []
9+
810
if model_str
911
model_from_string(model_str)
1012
elsif model_file
@@ -23,6 +25,7 @@ def initialize(params: nil, train_set: nil, model_file: nil, model_str: nil)
2325
create_handle do |handle|
2426
safe_call FFI.LGBM_BoosterCreate(train_set.handle, params_str(params), handle)
2527
end
28+
@refs << train_set
2629
end
2730

2831
self.best_iteration = -1
@@ -33,6 +36,7 @@ def initialize(params: nil, train_set: nil, model_file: nil, model_str: nil)
3336

3437
def add_valid(data, name)
3538
safe_call FFI.LGBM_BoosterAddValidData(@handle, data.handle)
39+
@refs << data
3640
@name_valid_sets << name
3741
self # consistent with Python API
3842
end

lib/lightgbm/dataset.rb

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -183,11 +183,7 @@ def construct
183183

184184
safe_call FFI.LGBM_DatasetCreateFromMat(c_data, FFI::C_API_DTYPE_FLOAT64, nrow, ncol, 1, parameters, reference, handle)
185185
end
186-
if used_indices
187-
@handle = handle.read_pointer
188-
else
189-
@handle = ::FFI::AutoPointer.new(handle.read_pointer, FFI.method(:LGBM_DatasetFree))
190-
end
186+
@handle = ::FFI::AutoPointer.new(handle.read_pointer, FFI.method(:LGBM_DatasetFree))
191187

192188
self.label = @label if @label
193189
self.weight = @weight if @weight

0 commit comments

Comments
 (0)