-
-
Save ajkur/b5e1f7908d1d2a1f2c43b82690cc82e9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from numba import jit | |
import resource | |
# Memory Leak Example | |
def aFun(N): | |
@jit(nopython=True) | |
def aLoop(N): | |
return N | |
return aLoop(N) | |
M = 100 | |
N = 10 | |
for k in range(M): | |
aFun(N) | |
if k%10 == 0: | |
print 'Memory usage at iteration %i: %s (kb)' % (k,resource.getrusage(resource.RUSAGE_SELF).ru_maxrss) | |
# Workaround | |
@jit(nopython=True) | |
def bLoop(N): | |
return N | |
def bFun(bLoop,N): | |
return bLoop(N) | |
for k in range(M): | |
bFun(bLoop,N) | |
if k%10 == 0: | |
print 'Memory usage at iteration %i: %s (kb)' % (k,resource.getrusage(resource.RUSAGE_SELF).ru_maxrss) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment