• <small id='cuFmz'></small><noframes id='cuFmz'>

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

        在python中查找对对象的所有引用

        Find all references to an object in python(在python中查找对对象的所有引用)
            <tbody id='H8JrQ'></tbody>
        • <tfoot id='H8JrQ'></tfoot>
        • <legend id='H8JrQ'><style id='H8JrQ'><dir id='H8JrQ'><q id='H8JrQ'></q></dir></style></legend>

        • <small id='H8JrQ'></small><noframes id='H8JrQ'>

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

                1. <i id='H8JrQ'><tr id='H8JrQ'><dt id='H8JrQ'><q id='H8JrQ'><span id='H8JrQ'><b id='H8JrQ'><form id='H8JrQ'><ins id='H8JrQ'></ins><ul id='H8JrQ'></ul><sub id='H8JrQ'></sub></form><legend id='H8JrQ'></legend><bdo id='H8JrQ'><pre id='H8JrQ'><center id='H8JrQ'></center></pre></bdo></b><th id='H8JrQ'></th></span></q></dt></tr></i><div id='H8JrQ'><tfoot id='H8JrQ'></tfoot><dl id='H8JrQ'><fieldset id='H8JrQ'></fieldset></dl></div>
                  本文介绍了在python中查找对对象的所有引用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  在 python 中查找对象的所有引用的好方法是什么?

                  我问的原因是看起来我们有内存泄漏".我们正在从 Web 浏览器将图像文件上传到服务器.每次我们这样做时,服务器上的内存使用量与刚刚上传的文件的大小成正比.这个内存永远不会被python垃圾收集释放,所以我认为可能有指向图像数据的杂散引用没有被删除或超出范围,即使在每个请求结束时也是如此.

                  The reason I ask is that it looks like we have a "memory leak". We are uploading image files to the server from a web browser. Each time we do this, the memory usage on the server goes up proportionately to the size of the file that was just uploaded. This memory is never getting released by the python garbage collection, so I'm thinking that there are probably stray references pointing to the image data that are not getting deleted or going out of scope, even at the end of each request.

                  我认为能够问 python 会很好:哪些引用仍然指向这个内存?"这样我就可以弄清楚是什么阻止了垃圾收集器释放它.

                  I figure it would be nice to be able to ask python: "What references are still pointing to this memory?" so that I can figure out what is keeping the garbage collection from freeing it.

                  目前我们在 Heroku 服务器上运行 Python 和 Django.

                  Currently we are running Python and Django on a Heroku server.

                  推荐答案

                  Python 的标准库有 gc 模块,其中包含垃圾收集器 API.您可能想要的功能之一是

                  Python's standard library has gc module containing garbage collector API. One of the function you possible want to have is

                  gc.get_objects()
                  

                  此函数返回垃圾收集器当前跟踪的所有对象的列表.下一步是对其进行分析.

                  This function returns list of all objects currently tracked by garbage collector. The next step is to analyze it.

                  如果您知道要跟踪的对象,可以使用 sys 模块的 getrefcount 函数:

                  If you know the object you want to track you can use sys module's getrefcount function:

                  >>> x = object()
                  >>> sys.getrefcount(x)
                  2
                  >>> y = x
                  >>> sys.getrefcount(x)
                  3
                  

                  这篇关于在python中查找对对象的所有引用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  env: python: No such file or directory(env: python: 没有这样的文件或目录)
                  How to evaluate environment variables into a string in Python?(如何在 Python 中将环境变量评估为字符串?)
                  Python - temporarily modify the current process#39;s environment(Python - 临时修改当前进程的环境)
                  Change current process environment#39;s LD_LIBRARY_PATH(更改当前进程环境的 LD_LIBRARY_PATH)
                  Reading and writing environment variables in Python?(在 Python 中读写环境变量?)
                  When to use sys.path.append and when modifying %PYTHONPATH% is enough(何时使用 sys.path.append 以及何时修改 %PYTHONPATH% 就足够了)

                      <tbody id='MD4aQ'></tbody>

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