Numba: memory leak when using map()

Created on 11 Sep 2020  路  3Comments  路  Source: numba/numba

Reporting a bug

  • [x] I have tried using the latest released version of Numba (most recent is
    visible in the change log (https://github.com/numba/numba/blob/master/CHANGE_LOG).

  • [x] I have included below a minimal working reproducer (if you are unsure how
    to write one see http://matthewrocklin.com/blog/work/2018/02/28/minimal-bug-reports).

Environment

OS: 64bit Mac OS X 10.14.6 18G4032
Kernel: x86_64 Darwin 18.7.0
CPU: Intel Core i7-4750HQ @ 2.00GHz
$ python --version
Python 3.8.2
$ python -c 'import numba; print(numba.__version__)'
0.51.2

List comprehension version

import numpy as np
import numba


@numba.njit
def list_comp(arr):
    [np.log(x) for x in arr]


arr = np.arange(10)
for _ in range(10000):
    list_comp(arr)

stats = numba.core.runtime.rtsys.get_allocation_stats()
print("stats:", stats.alloc - stats.free)
stats: 0

map() version

import numpy as np
import numba


@numba.njit
def list_comp(arr):
    map(np.log, arr)


arr = np.arange(10)
for _ in range(10000):
    list_comp(arr)

stats = numba.core.runtime.rtsys.get_allocation_stats()
print("stats:", stats.alloc - stats.free)
stats: 10000

I really liked using numba, thanks for all the hard work building it.

This seems related to bugs with yield, but a yield isn't used here, which makes this bug really hard to find.
I hope this gets taken care of.

bug - memory leak

All 3 comments

Thanks for the report and kind words, glad you like Numba. I can reproduce what you see and suspect that this is because internally Numba's map yields:

https://github.com/numba/numba/blob/c448052c875d7a84e8d067f8483a1a1caa1dfe9b/numba/cpython/builtins.py#L609-L614

Dupe of #5350?

Technically I think yes, but I'm inclined to leave this as a direct reminder that the map builtin is leaking. Thanks!

Was this page helpful?
0 / 5 - 0 ratings