how to release used memory immediately in python list?

后端 未结 5 1648
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-02 12:33

in many cases ,you are sure you definitely won\'t use the list again,i hope the memory should be release right now

a = [11,22,34,567,9999]
del a
5条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-02 13:03

    If your worried about memory management and performance for data types why not use something like a linked double queue.

    First its memory footprint is scattered though out the memory so you won't have to allocate a large chunk of continuous memory right off the bat.

    Second you will see faster access times for enqueueing and dequeueing because unlike in a standard list when you remove lets say a middle element there is no need for sliding the rest of the list over in the index which takes time in large lists.

    I should also note if you are using just integers I would suggest looking into a binary heap as you will see O(log^2n) access times compared to mostly O(N) with lists.

提交回复
热议问题