1 | | See https://ask.sagemath.org/question/43769/memory-leaks-with-matrix-multiplication-over-gf2/ |

| 1 | As reported on [https://ask.sagemath.org/question/43769/memory-leaks-with-matrix-multiplication-over-gf2/ this ask question]: |

| 2 | |

| 3 | {{{ |

| 4 | n = 8 |

| 5 | X = zero_vector(GF(2), n) |

| 6 | M = zero_matrix(GF(2), n, n) |

| 7 | |

| 8 | for _ in range(10000000): |

| 9 | Y = M * X |

| 10 | }}} |

| 11 | |

| 12 | leads to: |

| 13 | |

| 14 | {{{ |

| 15 | m4ri_mm_malloc: malloc returned NULL |

| 16 | --------------------------------------------------------------------------- |

| 17 | RuntimeError Traceback (most recent call last) |

| 18 | <ipython-input-1-04da27075a1c> in <module>() |

| 19 | 4 |

| 20 | 5 for _ in range(Integer(10000000)): |

| 21 | ----> 6 Y = M * X |

| 22 | 7 |

| 23 | |

| 24 | /opt/sagemath/sage-source/local/lib/python2.7/site-packages/sage/structure/element.pyx in sage.structure.element.Matrix.__mul__ (build/cythonized/sage/structure/element.c:23537)() |

| 25 | 3666 return (<Matrix>left)._matrix_times_matrix_(<Matrix>right) |

| 26 | 3667 if BOTH_ARE_ELEMENT(cl): |

| 27 | -> 3668 return coercion_model.bin_op(left, right, mul) |

| 28 | 3669 |

| 29 | 3670 cdef long value |

| 30 | |

| 31 | /opt/sagemath/sage-source/local/lib/python2.7/site-packages/sage/structure/coerce.pyx in sage.structure.coerce.CoercionModel_cache_maps.bin_op (build/cythonized/sage/structure/coerce.c:9757)() |

| 32 | 1173 action = self.get_action(xp, yp, op, x, y) |

| 33 | 1174 if action is not None: |

| 34 | -> 1175 return (<Action>action)._call_(x, y) |

| 35 | 1176 |

| 36 | 1177 try: |

| 37 | |

| 38 | /opt/sagemath/sage-source/local/lib/python2.7/site-packages/sage/matrix/action.pyx in sage.matrix.action.MatrixVectorAction._call_ (build/cythonized/sage/matrix/action.c:5997)() |

| 39 | 325 else: |

| 40 | 326 v = v.dense_vector() |

| 41 | --> 327 return A._matrix_times_vector_(v) |

| 42 | 328 |

| 43 | 329 |

| 44 | |

| 45 | /opt/sagemath/sage-source/local/lib/python2.7/site-packages/sage/matrix/matrix_mod2_dense.pyx in sage.matrix.matrix_mod2_dense.Matrix_mod2_dense._matrix_times_vector_ (build/cythonized/sage/matrix/matrix_mod2_dense.c:6487)() |

| 46 | 573 return VS.zero() |

| 47 | 574 cdef Vector_mod2_dense c = Vector_mod2_dense.__new__(Vector_mod2_dense) |

| 48 | --> 575 sig_str("matrix allocation failed") |

| 49 | 576 c._init(self._nrows, VS) |

| 50 | 577 c._entries = mzd_init(1, self._nrows) |

| 51 | |

| 52 | RuntimeError: matrix allocation failed |

| 53 | }}} |