fix swig ownership when assigning to struct pointer field
Summary: When faiss is called from SWIG, it is usually assumed that Python will do all the memory management, therefore assigning to a pointer in C++ should not transfer ownerhsip (default SWIG behavior). This diff fixed that.
Differential Revision: D51529085
This pull request was exported from Phabricator. Differential Revision: D51529085
hopefully this will finally fix https://github.com/facebookresearch/faiss/issues/2996
@mdouze do we still need this one?
Even though the final assert fails since the ownership disappears, it seems like the memory does not increase. This typemap looks right to me when I test it. We can discuss on next steps.
Current status after discussion:
ASAN does not seem to detect these Python memory leaks. There are no ASAN errors in a simple repro unit test like
def test_ownership_2(self):
d = 32
quantizer = faiss.IndexFlatL2(d)
quantizer.this.own(False)
The destructor of IndexFlatL2 does not get called when quantizer.this.own(False). Removing this line will call the destructor.
We should introduce some Python unit test to catch these memory leaks.