2

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

TassosK
  • 293
  • 3
  • 16
  • Possible duplicate of [Different ways of clearing lists](https://stackoverflow.com/questions/850795/different-ways-of-clearing-lists) – Xantium Jun 02 '18 at 19:49

2 Answers2

3

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.

Mike Scotty
  • 10,530
  • 5
  • 38
  • 50
1

just do

del array

instead of

del(array[:])