Why can't objgraph capture the growth of np.array()?

前端 未结 1 1393
感情败类
感情败类 2021-01-21 05:29

See the code:

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.ran         


        
相关标签:
1条回答
  • 2021-01-21 06:13

    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 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.

    0 讨论(0)
提交回复
热议问题