Skip to content

Fix memory leak warning for unordered_multimap in IndexIVFFlatDedup Python binding (#1667)#5145

Open
anishesg wants to merge 1 commit intofacebookresearch:mainfrom
anishesg:fix/ph-issue-1667
Open

Fix memory leak warning for unordered_multimap in IndexIVFFlatDedup Python binding (#1667)#5145
anishesg wants to merge 1 commit intofacebookresearch:mainfrom
anishesg:fix/ph-issue-1667

Conversation

@anishesg
Copy link
Copy Markdown

When running the Python test suite, SWIG emits a warning:

swig/python detected a memory leak of type 'std::unordered_multimap< faiss::Index::idx_t,faiss::Index::idx_t > *', no destructor found.

The root cause is that faiss::IndexIVFFlatDedup::instances is a std::unordered_multimap<idx_t, idx_t> member, and SWIG has no built-in destructor registration for that STL type. When SWIG wraps the field, it generates a raw pointer wrapper with no cleanup, causing the leak warning whenever an IndexIVFFlatDedup object is garbage-collected on the Python side.

The fix adds %ignore faiss::IndexIVFFlatDedup::instances in faiss/python/swigfaiss.swig before the %include <faiss/IndexIVFFlat.h> directive. This prevents SWIG from generating the untyped wrapper for the internal dedup map (which was never exposed in the Python type stubs anyway) and eliminates the memory leak warning.

Fixes #1667

…ython binding (facebookresearch#1667)

When running the Python test suite, SWIG emits a warning:

Signed-off-by: anish k <ak8686@princeton.edu>
@meta-cla meta-cla Bot added the CLA Signed label Apr 24, 2026
@anishesg anishesg marked this pull request as ready for review April 25, 2026 00:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Warning of memory leak when running test suite

1 participant