The following should clarify the situation a bit:
>>> s = 'abcd' >>> arr = np.frombuffer(buffer(s), dtype='uint8') >>> arr.base <read-only buffer for 0x03D1BA60, size -1, offset 0 at 0x03D1BA00> >>> del s >>> arr.base <read-only buffer for 0x03D1BA60, size -1, offset 0 at 0x03D1BA00>
In the first case, del s has no effect, because what the array indicates is a buffer created from it, which is not mentioned anywhere.
>>> t = buffer('abcd') >>> arr = np.frombuffer(t, dtype='uint8') >>> arr.base <read-only buffer for 0x03D1BA60, size -1, offset 0 at 0x03C8D920> >>> arr.base is t True >>> del t >>> arr.base <read-only buffer for 0x03D1BA60, size -1, offset 0 at 0x03C8D920>
In the second case, when you del t , you get rid of the variable t pointing to the buffer object, but since the array still has a reference to the same buffer , it is not deleted, although I'm not sure how to check this if you are now del arr , the buffer object should lose its last link and automatically collect garbage.
source share