简体   繁体   中英

Does CPython's garbage collection do compaction?

I was talking with a friend, comparing languages, and he mentioned that Java's automated memory management is superior to Python's as Java's does compaction, while Python's does not - and hence for long-running servers, Python is a poor choice.

Without getting into which is better or worse, is his claim true - does CPython's garbage collector not compact memory and, thus, long-running Python processes get more and more fragmented over time?

I know that running CPython's garbage collector is optional. Mostly it uses automated reference counting for automated memory management, and as soon as a reference count hits zero, the object is freed - thus the only thing that CPython's garbage collector is needed for, in terms of freeing objects, is to detect cycles which no object in the root set has a reference to. But I don't know the details of whether it does any compaction in addition to that.

If it does not, then how do long-running CPython processes address the memory fragmentation issue?

我不确定,但CPython使用引用计数 ,它的对象使用内存地址作为ID,所以我会说它不做压缩...而且根据这个 ,“[C] Python不使用内存压缩.. 。[] Python应该使用内存压缩,实现C扩展会更加繁琐且容易出错,并且会有更少的扩展 - 限制使用Python的域。“

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM