-
-
Notifications
You must be signed in to change notification settings - Fork 697
Open
Labels
Description
def __dealloc__(self):
"""
Frees all the memory allocated for this matrix.
EXAMPLE:
sage: a = Matrix(ZZ,2,[1,2,3,4])
sage: del a
"""
cdef Py_ssize_t i
if self._initialized:
for i from 0 <= i < (self._nrows * self._ncols):
mpz_clear(self._entries[i])
sage_free(self._entries)
sage_free(self._matrix)
It is possible that _initialized is not set but _matrix and _entries are allocated.
Error paths in __new__ and __init__ should also be revised, since if one raises an error in these functions python still calls __dealloc__ for the cleanup.
From the __init__ function:
elif isinstance(entries, (int,long)) or is_Element(entries):
try:
x = ZZ(entries)
except TypeError:
self._initialized = False
raise TypeError, "unable to coerce entry to an integer"
Component: memleak
Issue created by migration from https://trac.sagemath.org/ticket/4883