Python deep getsizeof list with contents?

后端 未结 5 1853
[愿得一人]
[愿得一人] 2020-12-01 10:44

I was surprised that sys.getsizeof( 10000*[x] ) is 40036 regardless of x: 0, \"a\", 1000*\"a\", {}.
Is there a deep_getsizeof which properly co

5条回答
  •  遥遥无期
    2020-12-01 11:31

    mylist = 10000 * [x] means create a list of size 10000 with 10000 references to object x.

    Object x is not copied - only a single one exists in memory!!!

    So to use getsizeof, it would be: sys.getsizeof(mylist) + sys.getsizeof(x)

提交回复
热议问题