<tfoot id='EwKRg'></tfoot>
    • <bdo id='EwKRg'></bdo><ul id='EwKRg'></ul>
  • <i id='EwKRg'><tr id='EwKRg'><dt id='EwKRg'><q id='EwKRg'><span id='EwKRg'><b id='EwKRg'><form id='EwKRg'><ins id='EwKRg'></ins><ul id='EwKRg'></ul><sub id='EwKRg'></sub></form><legend id='EwKRg'></legend><bdo id='EwKRg'><pre id='EwKRg'><center id='EwKRg'></center></pre></bdo></b><th id='EwKRg'></th></span></q></dt></tr></i><div id='EwKRg'><tfoot id='EwKRg'></tfoot><dl id='EwKRg'><fieldset id='EwKRg'></fieldset></dl></div>
  • <small id='EwKRg'></small><noframes id='EwKRg'>

    <legend id='EwKRg'><style id='EwKRg'><dir id='EwKRg'><q id='EwKRg'></q></dir></style></legend>

        为什么python对gc同时使用引用计数和mark-and-sweep?

        时间:2023-07-05

                <tbody id='eof7O'></tbody>

              <small id='eof7O'></small><noframes id='eof7O'>

            1. <legend id='eof7O'><style id='eof7O'><dir id='eof7O'><q id='eof7O'></q></dir></style></legend>
              • <bdo id='eof7O'></bdo><ul id='eof7O'></ul>

              • <i id='eof7O'><tr id='eof7O'><dt id='eof7O'><q id='eof7O'><span id='eof7O'><b id='eof7O'><form id='eof7O'><ins id='eof7O'></ins><ul id='eof7O'></ul><sub id='eof7O'></sub></form><legend id='eof7O'></legend><bdo id='eof7O'><pre id='eof7O'><center id='eof7O'></center></pre></bdo></b><th id='eof7O'></th></span></q></dt></tr></i><div id='eof7O'><tfoot id='eof7O'></tfoot><dl id='eof7O'><fieldset id='eof7O'></fieldset></dl></div>
                • <tfoot id='eof7O'></tfoot>

                  本文介绍了为什么python对gc同时使用引用计数和mark-and-sweep?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我的问题是为什么 python 对 gc 使用引用计数和标记和清除?为什么不只是标记和清除?

                  My question is why does python use both reference counting and mark-and-sweep for gc? Why not only mark-and-sweep?

                  我最初的猜测是,使用引用计数可以轻松删除非循环引用的对象,这可能会在一定程度上加快标记和清除并立即获得内存.不知道我猜对了吗?

                  My initial guess is that using reference counting can easily remove non-cyclic referenced objects, this may somewhat speed up mark-and-sweep and gain memory immediately. Don't know if my guess is right?

                  有什么想法吗?

                  非常感谢.

                  推荐答案

                  Python(该语言)没有说明它使用哪种形式的垃圾回收.主要实现(通常称为 CPython)就像您描述的那样.其他版本(例如 Jython 或 IronPython)使用纯粹的垃圾收集系统.

                  Python (the language) doesn't say which form of garbage collection it uses. The main implementation (often known as CPython) acts as you describe. Other versions such as Jython or IronPython use a purely garbage collected system.

                  是的,使用引用计数的早期集合有一个好处,但 CPython 使用它的主要原因是历史性的.最初没有针对循环对象的垃圾收集,因此循环导致内存泄漏.C API 和数据结构主要基于引用计数原则.添加真正的垃圾回收后,无法破坏现有的二进制 API 和所有依赖它们的库,因此必须保留引用计数.

                  Yes, there is a benefit of earlier collection with reference counting, but the main reason CPython uses it is historical. Originally there was no garbage collection for cyclic objects so cycles led to memory leaks. The C APIs and data structures are based heavily around the principle of reference counting. When real garbage collection was added it wasn't an option to break the existing binary APIs and all the libraries that depended on them so the reference counting had to remain.

                  这篇关于为什么python对gc同时使用引用计数和mark-and-sweep?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:对于打开的行(文件名) 下一篇:Python del 语句

                  相关文章

                • <legend id='rGhHR'><style id='rGhHR'><dir id='rGhHR'><q id='rGhHR'></q></dir></style></legend>

                    • <bdo id='rGhHR'></bdo><ul id='rGhHR'></ul>

                  1. <small id='rGhHR'></small><noframes id='rGhHR'>

                  2. <tfoot id='rGhHR'></tfoot>

                    1. <i id='rGhHR'><tr id='rGhHR'><dt id='rGhHR'><q id='rGhHR'><span id='rGhHR'><b id='rGhHR'><form id='rGhHR'><ins id='rGhHR'></ins><ul id='rGhHR'></ul><sub id='rGhHR'></sub></form><legend id='rGhHR'></legend><bdo id='rGhHR'><pre id='rGhHR'><center id='rGhHR'></center></pre></bdo></b><th id='rGhHR'></th></span></q></dt></tr></i><div id='rGhHR'><tfoot id='rGhHR'></tfoot><dl id='rGhHR'><fieldset id='rGhHR'></fieldset></dl></div>