Skip to content

Commit

Permalink
Merge pull request #262 from benfred/memfix
Browse files Browse the repository at this point in the history
Fix Memory Leak in Python Bindings.
  • Loading branch information
Leonid Boytsov authored and GitHub committed Dec 11, 2017
2 parents a69becb + 782b690 commit 4676e8d
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions python_bindings/nmslib.cc
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,7 @@ struct IndexWrapper {
}

~IndexWrapper() {
LOG(LIB_DEBUG) << "Destroying Index";
freeObjectVector(&data);
}

Expand Down Expand Up @@ -386,17 +387,17 @@ PYBIND11_PLUGIN(nmslib) {
switch (dtype) {
case DISTTYPE_FLOAT: {
auto index = new IndexWrapper<float>(method, space, space_params, data_type, dtype);
ret = py::cast(index);
ret = py::cast(index, py::return_value_policy::take_ownership);
break;
}
case DISTTYPE_DOUBLE: {
auto index = new IndexWrapper<double>(method, space, space_params, data_type, dtype);
ret = py::cast(index);
ret = py::cast(index, py::return_value_policy::take_ownership);
break;
}
case DISTTYPE_INT: {
auto index = new IndexWrapper<int>(method, space, space_params, data_type, dtype);
ret = py::cast(index);
ret = py::cast(index, py::return_value_policy::take_ownership);
break;
}
default:
Expand Down

0 comments on commit 4676e8d

Please sign in to comment.