TassosK
TassosK

Reputation: 293

Deleting a list in python, getsizeof() non zero?

I'm playing with python lists and I want to delete from memory a list when it's not used.(I have large data lists maybe thousands or million of elements..data type-> float)

I tried this code to see how deletion works in python(example)

import sys
array=[[12,34,54],[23,45,54,67]]
print(sys.getsizeof(array))  # it gives me result 80

#then
del(array[:])
print(sys.getsizeof(array)) #it gives me result 64?

why is that happens?shouldn't it be zero? Is there some overhead? just curious

Upvotes: 2

Views: 75

Answers (2)

Mike Scotty
Mike Scotty

Reputation: 10782

You're not deleting the list, you're only deleting the content.

64 is simply the size in memory of an empty list:

print(sys.getsizeof([])) # 64

Every object requires space in the memory, until it's completely deleted, even an empty string or None.

Upvotes: 3

mohammed thaha jk
mohammed thaha jk

Reputation: 156

just do

del array

instead of

del(array[:])

Upvotes: 1

Related Questions