[Numpy-discussion] Tracking and inspecting numpy objects

Robert Kern robert.kern at gmail.com
Mon Sep 15 08:07:16 EDT 2014

On Mon, Sep 15, 2014 at 12:31 PM, Eelco Hoogendoorn
<hoogendoorn.eelco at gmail.com> wrote:
> I figured the reference to the object through the local scope would also be
> tracked by the GC somehow, since the entire stack frame can be regarded as a
> separate object itself, but apparently not.

Objects are "tracked", not references. An object is only considered
"tracked" by the cyclic GC if the cyclic GC needs to traverse the
object's referents when looking for cycles. It is not necessarily
"tracked" just because it is referred to by an object that is
"tracked". If an object does not refer to other objects, *OR* if such
references cannot create a cycle for whatever reason, then the object
does not need to be tracked by the GC. Most ndarrays fall in that
second category. They do have references to their base ndarray, if a
view, and their dtype object, but under most circumstances these
cannot cause a cycle. As Sebastian mentioned, though, dtype=object
arrays can create cycles and should be tracked. We need to implement
the "tp_traverse" slot in order to do so.

Robert Kern

More information about the NumPy-Discussion mailing list