1. <tfoot id='AjBfy'></tfoot>

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

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

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

      如何在 Python 中删除对象的每个引用?

      时间:2023-07-05

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

          <small id='5YAz2'></small><noframes id='5YAz2'>

          1. <tfoot id='5YAz2'></tfoot>
                本文介绍了如何在 Python 中删除对象的每个引用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                假设你有类似的东西:

                x = "something"
                b = x
                l = [b]
                

                如何删除只有一个引用的对象,比如 x?

                How can you delete the object only having one reference, say x?

                del x 不会成功;例如,该对象仍然可以从 b 访问.

                del x won't do the trick; the object is still reachable from b, for example.

                推荐答案

                不不不.Python 有一个垃圾收集器,它有非常严重的领域问题——它不会干扰你创建对象,也不会干扰它删除对象.

                No no no. Python has a garbage collector that has very strong territory issues - it won't mess with you creating objects, you don't mess with it deleting objects.

                简而言之,这是不可能的,而且是有充分理由的.

                Simply put, it can't be done, and for a good reason.

                例如,如果您的需求来自例如缓存算法保留引用的情况,但不应阻止数据在没有人使用时被垃圾收集,您可能想看看 weakref.

                If, for instance, your need comes from cases of, say, caching algorithms that keep references, but should not prevent data from being garbage collected once no one is using it, you might want to take a look at weakref.

                这篇关于如何在 Python 中删除对象的每个引用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                上一篇:Python del 语句 下一篇:Python GC 也会关闭文件吗?

                相关文章

                  <bdo id='8pwV3'></bdo><ul id='8pwV3'></ul>

                  <legend id='8pwV3'><style id='8pwV3'><dir id='8pwV3'><q id='8pwV3'></q></dir></style></legend>

                1. <small id='8pwV3'></small><noframes id='8pwV3'>

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