为什么objgraph无法捕获np.array()的增长? [英] Why can't objgraph capture the growth of np.array()?

查看:140
本文介绍了为什么objgraph无法捕获np.array()的增长?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

查看代码:

import objgraph
import numpy as np
objgraph.show_growth()
j = 20
y = []
for i in range(5):
    for l in range(j):
        y.append(np.array([np.random.randint(500),np.random.randint(500)]))
    print 'i:',i
    objgraph.show_growth()
    print '___'
    #objgraph.show_most_common_types(limit=100)
    j += 1

结果是:

i: 1
wrapper_descriptor 1596 +3
weakref 625 +1
dict 870 +1
method_descriptor 824 +1
i: 2
i: 3
i: 4

对于2、3和4时代,它没有显示任何增长.但它应该表明numpy.array的数量在增加

For the 2,3 and 4 epoch, it shows nothing growing. But it should show that the number of numpy.array grows

推荐答案

我对objgraph不太熟悉,但是我认为同一问题也适用于其他Python堆分析工具,例如

I'm not that familiar with objgraph specifically, but I think the same issue applies to other Python heap analysis tools such as heapy.

Numpy数组是用C实现的,它们在内部通过自己的引用计数调用Py_INCREFPy_DECREF.因此,Python 垃圾收集器不会对其进行跟踪.像heapy和(大概)objgraph这样的工具使用Python垃圾收集器来跟踪对对象的引用,因此,numpy数组对它们不可见.

Numpy arrays are implemented in C, and do their own reference counting by internally calling Py_INCREF and Py_DECREF. As such, they are not tracked by the Python garbage collector. Tools like heapy and (presumably) objgraph use the Python garbage collector to track references to objects, so as a result numpy arrays are invisible to them.

这篇关于为什么objgraph无法捕获np.array()的增长?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆