From 0592817cfe5e1221bf2162717f39dd12306eebf0 Mon Sep 17 00:00:00 2001
From: Martin Larralde <martin.larralde@embl.de>
Date: Wed, 3 Aug 2022 05:07:07 +0200
Subject: [PATCH] Make `_Map` deallocate the compute map when garbage collected

---
 pyfastani/_fastani.pyx | 26 ++++++++++++++++++++++++++
 1 file changed, 26 insertions(+)

diff --git a/pyfastani/_fastani.pyx b/pyfastani/_fastani.pyx
index 456d0c6..9816528 100644
--- a/pyfastani/_fastani.pyx
+++ b/pyfastani/_fastani.pyx
@@ -287,12 +287,38 @@ cdef int _add_minimizers_prot(
 
 
 cdef class _Map:
+    """A private class wrapping a heap-allocated compute map.
+    """
+
+    # --- Attributes ---------------------------------------------------------
+
     cdef Map_t* _map
 
+    # --- Magic methods ------------------------------------------------------
+
+    def __cinit__(self):
+        self._map = NULL
+
+    def __init__(self):
+        raise TypeError(f"Cannot instantiate objects of type {type(self).__name__!r}")
+
+    def __dealloc__(self):
+        del self._map
+
 
 cdef class _FinalMappings:
+    """A private class wrapping a vector of L2 mapping results.
+    """
+
+    # --- Attributes ---------------------------------------------------------
+
     cdef atomic_vector[MappingResult_t] _vec
 
+    # --- Magic methods ------------------------------------------------------
+
+    def __init__(self):
+        raise TypeError(f"Cannot instantiate objects of type {type(self).__name__!r}")
+
 
 cdef class _Parameterized:
     """A base class for types wrapping a `skch::Parameters` C++ object.
-- 
GitLab