Skip to content

Commit

Permalink
expose freeProblem outside finaliser
Browse files Browse the repository at this point in the history
  • Loading branch information
yeesian committed Oct 19, 2014
1 parent e430f16 commit 2dd22dd
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
2 changes: 2 additions & 0 deletions examples/hs015_tuner.jl
Original file line number Diff line number Diff line change
Expand Up @@ -86,3 +86,5 @@ solveProblem(kp)
@test_approx_eq_eps kp.x[1] 0.5 1e-4
@test_approx_eq_eps kp.x[2] 2.0 1e-4
@test_approx_eq_eps kp.obj_val[1] 306.5 0.02

freeProblem(kp)
14 changes: 9 additions & 5 deletions src/KNITRO.jl
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ module KNITRO

export
KnitroProblem,
createProblem, #freeProblem,
createProblem, freeProblem,
initializeProblem,
solveProblem,
restartProblem,
Expand Down Expand Up @@ -57,17 +57,21 @@ module KNITRO
function KnitroProblem()
prob = new(newcontext())
# finalizer segfaults upon termination of the running script
finalizer(prob, freeProblem)
# finalizer(prob, freeProblem)
prob
end
end

createProblem() = KnitroProblem()

function freeProblem(kp::KnitroProblem)
println("KNITRO.jl: freeing problem")
freecontext(kp.env)
println("KNITRO.jl: problem freed")
println("KNITRO: calling freecontext on $(kp.env)")
println("C_NULL (for reference): $(C_NULL)")
return_code = @ktr_ccall(free, Int32, (Ptr{Void},), pointer_from_objref(kp.env))
if return_code != 0
error("KNITRO: Error freeing memory")
end
println("KNITRO: freecontext successful")
kp.env = C_NULL
println("KNITRO.jl: set env to C_NULL")
end
Expand Down

0 comments on commit 2dd22dd

Please sign in to comment.