Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Keep SVMProblem from being garbage-collected #2

Closed
dmsc opened this issue Oct 17, 2013 · 0 comments
Closed

Keep SVMProblem from being garbage-collected #2

dmsc opened this issue Oct 17, 2013 · 0 comments

Comments

@dmsc
Copy link

dmsc commented Oct 17, 2013

From libsvm help:

NOTE Because svm_model contains pointers to svm_problem, you can
not free the memory used by svm_problem if you are still using the
svm_model produced by svm_train().

This causes LIBSVM package to randomly fail if julia garbage-collects the SVMProblem and nodes before calling svmpredict.

This patch solves the isue:

diff --git a/src/LIBSVM.jl b/src/LIBSVM.jl
index f50b760..b1d72e5 100644
--- a/src/LIBSVM.jl
+++ b/src/LIBSVM.jl
@@ -66,6 +66,9 @@ end
 type SVMModel{T}
     ptr::Ptr{Void}
     param::Vector{SVMParameter}
+    problem::Vector{SVMProblem}
+    nodes::Array{SVMNode,2}
+    nodeptr::Vector{Ptr{SVMNode}}
     labels::Vector{T}
     weight_labels::Vector{Int32}
     weights::Vector{Float64}
@@ -224,7 +227,7 @@ function svmtrain{T, U<:Real}(labels::AbstractVector{T},
     ptr = ccall(svm_train(), Ptr{Void}, (Ptr{SVMProblem},
         Ptr{SVMParameter}), problem, param)

-    model = SVMModel(ptr, param, reverse_labels, weight_labels, weights,
+    model = SVMModel(ptr, param, problem, nodes, nodeptrs, reverse_labels, weight_labels, weights,
         size(instances, 1), verbose)
     finalizer(model, svmfree)
     model
mpastell added a commit that referenced this issue Apr 19, 2017
barucden pushed a commit to barucden/LIBSVM.jl that referenced this issue Jan 28, 2024
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

No branches or pull requests

1 participant