Skip to content

Commit 1d31d14

Browse files
committed
add finalizer to SCIPModel
1 parent 9592057 commit 1d31d14

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

src/types.jl

+8-1
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,18 @@ type SCIPModel
1313
# TODO: check return code (everywhere!)
1414
ccall((:CSIPcreateModel, libcsip), Cint, (Ptr{Ptr{Void}}, ), _arr)
1515
m = new(_arr[1], options)
16-
# QUESTION: Why is _arr not garbage-collected?
16+
@assert m.ptr_model != C_NULL
17+
18+
finalizer(m, freescip)
1719
return m
1820
end
1921
end
2022

23+
function freescip(m::SCIPModel)
24+
@assert m.ptr_model != C_NULL
25+
_freeModel(m)
26+
end
27+
2128
# Linear Quadratic Model
2229

2330
type SCIPLinearQuadraticModel <: AbstractLinearQuadraticModel

src/wrapper.jl

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ function _patchVersion()
1010
ccall((:CSIPpatchVersion, libcsip), Cint, ())
1111
end
1212

13-
function _freeModel(model::SCIPMathProgModel)
14-
ccall((:CSIPfreeModel, libcsip), Cint, (Ptr{Void}, ), model.inner.ptr_model)
13+
function _freeModel(inner::SCIPModel)
14+
ccall((:CSIPfreeModel, libcsip), Cint, (Ptr{Void}, ), inner.ptr_model)
1515
end
1616

1717
function _addVar(model::SCIPMathProgModel, lowerbound::Cdouble,

0 commit comments

Comments
 (0)