Suppose that I have a large array:
A = numpy.arange(100000000)
and now I truncate it:
A = A[:10]
I used to think that, given that I don't have a name bound to the original A
any more, its reference count has dropped to zero and it will get garbage-collected. However, A.base
surreptitiously still refers to the original array! Does that mean that the only way to clear this up is by making an explicit copy, i.e.
A = A[:10].copy()
or is there some other way to, so to say, transfer primary ownership of the memory used to the new object, while the original can be garbage collected? I'm worried that this may be the source of subtle memory leaks in parts of my code.
(remotely related question: Memory-efficient way to truncate large array in Matlab)