Permalink
Browse files

added instance method destroy! to Rglpk::Problem

call this method explicitly to avoid memory leaking
  • Loading branch information...
1 parent 1b8112a commit 8be93cb7b4867e0881d9bf6d9216857620b2c782 @shaokun shaokun committed Dec 30, 2011
Showing with 12 additions and 0 deletions.
  1. +12 −0 lib/rglpk.rb
View
@@ -70,6 +70,14 @@ def initialize
Glpk_wrapper.glp_create_index(@lp)
end
+ def destroy!
+ Glpk_wrapper.glp_delete_prob(@lp)
+
+ Glpk_wrapper.delete_intArray(@_ia)
+ Glpk_wrapper.delete_intArray(@_ja)
+ Glpk_wrapper.delete_doubleArray(@_ar)
+ end
+
def name=(n)
Glpk_wrapper.glp_set_prob_name(@lp, n)
end
@@ -162,6 +170,10 @@ def set_matrix(v)
Glpk_wrapper.doubleArray_setitem(ar, y + 1, x)
end
+ @_ia = ia
+ @_ja = ja
+ @_ar = ar
+
Glpk_wrapper.glp_load_matrix(@lp, v.size, ia, ja, ar)
end

0 comments on commit 8be93cb

Please sign in to comment.