TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

Tracking Down a Python Memory Leak

150 点作者 bbernard超过 8 年前

7 条评论

guyzero超过 8 年前
&quot;What&#x27;s possible, though, is accumulating Python objects in memory and keeping strong references to them12. For instance, this happens when we build a cache (for example, a dict) that we never clear. The cache will hold references to every single item and the GC will never be able to destroy them, that is, unless the cache goes out of scope.&quot;<p>Back when I worked with a Java memory profiling tool (JProbe!) we called these &quot;lingerers&quot;. Not leaks, but the behaviour was similar.
评论 #13124614 未加载
评论 #13124477 未加载
评论 #13125418 未加载
tantalor超过 8 年前
Spoiler alert, the leak is in libxml2, not Python code.
评论 #13124516 未加载
评论 #13125408 未加载
评论 #13124445 未加载
评论 #13124507 未加载
评论 #13124970 未加载
评论 #13124446 未加载
mwcampbell超过 8 年前
The JVM community tends to prefer pure Java implementations of everything, rather than using existing C libraries like Python and Ruby. Some may see this as a bad thing, but it definitely has its benefits. One particularly relevant benefit in the context of this article is that the amount of code that can leak memory, in the conventional sense, is dramatically reduced. I suppose the same thing is happening in the Node.js ecosystem, though I don&#x27;t recall if Node uses native code to parse XML.
评论 #13127976 未加载
评论 #13127174 未加载
评论 #13127215 未加载
module0000超过 8 年前
tldr; libxml2&#x27;s C implementation leaked memory, author tracked it down. Kudos to the author for their persistence in digging down to the root of the problem. A lot of people would throw their hands up and decide to recycle the process every &lt;N&gt; seconds rather than analyze it to the depth the author did.
评论 #13125411 未加载
gravypod超过 8 年前
&gt; &quot;But if we&#x27;re strictly speaking about Python objects within pure Python code, then no, memory leaks are not possible - at least not in the traditional sense of the term. The reason is that Python has its own garbage collector (GC), so it should take care of cleaning up unused objects.&quot;<p>I have a hard time beliving this. Java can have memory leaks so why couldn&#x27;t Python?
评论 #13126992 未加载
评论 #13127279 未加载
评论 #13127027 未加载
dekhn超过 8 年前
I&#x27;ve used the gc module, with get_referers and get_referents, to track down various leaks. This only really helps with python-allocated object.<p>It&#x27;s trivial to end up with an unexpected strong reference. Weak references are the right way to deal with cache objects, imho.
评论 #13127399 未加载
评论 #13126102 未加载
partycoder超过 8 年前
Reminds me of myself tracing a memory leak in a node app loading a core dump into an IllumOS VM with mdb_v8. Not so simple&#x2F;friendly&#x2F;happy after all.<p>(You could argue that you could generate a heap snapshot with v8-profiler but I was against time).
评论 #13126539 未加载
评论 #13125966 未加载