i'm sure naive question python , garbage collection.
i have function creates large data structure in memory, , returns integer.
i expected after calling function, memory used data structure released.
however, if understand resource call below doing (thanks so post), not seem case. every call function, total memory used python appears increase. (i using python 2.7.1.)
import resource import random def r(n): = [random.randint(1,100) in range(1,n)] return n # or sum(a) resource.getrusage(resource.rusage_self).ru_maxrss z=r(100000) resource.getrusage(resource.rusage_self).ru_maxrss z=r(100000) resource.getrusage(resource.rusage_self).ru_maxrss
to get, e.g.:
81584128 84389888 85995520
why memory usage keep increasing?
thanks!
i think it's because each call function creating list a. have thought function exits list dumped , used space freed maybe that's not case or doesn't happen fast.
Comments
Post a Comment