3 回答
TA贡献1804条经验 获得超7个赞
PyObject_Malloc
int
PyInt_ClearFreeList()
gc.collect
.
import osimport gcimport psutil proc = psutil.Process(os.getpid())gc.collect()mem0 = proc.get_memory_info().rss# create approx. 10**7 int objects and pointersfoo = ['abc' for x in range(10**7)]mem1 = proc.get_memory_info().rss# unreference, including x == 9999999del foo, x mem2 = proc.get_memory_info().rss# collect() calls PyInt_ClearFreeList()# or use ctypes: pythonapi.PyInt_ClearFreeList()gc.collect()mem3 = proc.get_memory_info().rss pd = lambda x2, x1: 100.0 * (x2 - x1) / mem0print "Allocation: %0.2f%%" % pd(mem1, mem0)print "Unreference: %0.2f%%" % pd(mem2, mem1)print "Collect: %0.2f%%" % pd(mem3, mem2)print "Overall: %0.2f%%" % pd(mem3, mem0)
Allocation: 3034.36%Unreference: -752.39%Collect: -2279.74%Overall: 2.23%
mallopt
free
.
range
int
int
long
TA贡献1864条经验 获得超6个赞
为什么它特别发布了50.5mb-释放的数量是基于什么?
malloc
MADV_FREE
brk
munmap
MAP_FIXED
MADV_FREE
malloc
free
free
malloc
PyString
free
malloc
free
a malloc
munmap
brk
malloc
malloc
mmap
malloc
free
malloc
mmap
添加回答
举报