Python memory footprint vs. heap size

后端 未结 4 934
有刺的猬
有刺的猬 2020-12-28 21:41

I\'m having some memory issues while using a python script to issue a large solr query. I\'m using the solrpy library to interface with th

4条回答
  •  一个人的身影
    2020-12-28 22:14

    Python allocates Unicode objects from the C heap. So when you allocate many of them (along with other malloc blocks), then release most of them except for the very last one, C malloc will not return any memory to the operating system, as the C heap will only shrink on the end (not in the middle). Releasing the last Unicode object will release the block at the end of the C heap, which then allows malloc to return it all to the system.

    On top of these problems, Python also maintains a pool of freed unicode objects, for faster allocation. So when the last Unicode object is freed, it isn't returned to malloc right away, making all the other pages stuck.

提交回复
热议问题