如何追踪手柄泄漏?

发布于 2024-12-11 04:19:51 字数 212 浏览 0 评论 0原文

在我的一个应用程序中,我观察到句柄数量不断增加。在不使用应用程序的情况下,该数字大约每秒增加一次,因此后台处理代码的某些部分一定存在句柄泄漏。

如何追踪此类泄漏?有什么工具可以帮助解决这个问题吗?跟踪句柄泄漏时要寻找哪些模式?导致句柄泄漏的最常见错误是什么?

一堆问题,但我希望它们足够相关,可以将它们放在一个问题中。感谢您提前提供任何意见!

In one of my applications I observe an increasing number of handles. The number is incremented roughly every second without using the application, so there must be a handle leak in some part of the background processing code.

How can I trace such leaks? Are there any tools to help with this? What are the patterns to look for when tracing handle leaks? What are the most common mistakes that cause a handle leak?

A bunch of questions, but I hope they are related enough to put them in one question. Thanks for any input in advance!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

深海蓝天 2024-12-18 04:19:52

我建议使用Process Explorer。以管理员身份运行它以确保您看到所有相关数据。在那里您可以观察您的进程有哪些类型的句柄以及哪些句柄被过度创建且未释放。这应该可以帮助您缩小搜索范围(在我的例子中,由于对 winsocks 行为的一些错误假设,我的套接字到处泄漏。)。也许你可以把相关代码隔离出来贴在这里,让我们检查一下是否有问题。祝你好运!

I suggest using Process Explorer. Run it as Administrator to make sure you see all the relevant data. There you can observe what kind of handles your process has and which are excessively being created and not free'd. This should help you to narrow down the search (in my case, i had sockets leaking all over the place due to some false assumptions about the behaviour of winsocks.). Perhaps then you can isolate the relevant code and post it here for us to check if there is anything wrong. Good luck!

风启觞 2024-12-18 04:19:52

某些分析器(即 AQTime)可以分析 Windows 资源应用程序。如果您使用 XE,则可以使用 AQTime 的基本版本。

如果执行路径没有正确关闭句柄,则句柄泄漏很常见 - 但在 Windows 中,句柄是在许多不同情况下使用的非常常见的项目,您的应用程序正在泄漏哪种句柄?

Some profilers (i.e. AQTime) can profile Windows resource applications. If you're using XE, you have a basic version of AQTime available.

Handle leaks are common if an execution path doesn't close them properly - but a in Windows a handle is a very common item used in very many different situations, which kind of handles is your application leaking?

ㄟ。诗瑗 2024-12-18 04:19:52
  1. 在win10中,下载工具“Handle”
    https://learn.microsoft.com/en-us/sysinternals/downloads/句柄

  2. 用法:

    句柄[[-a] [-u] | [-c [-l] [-y]] | [-s]] [-p |> [名称]

  3. 示例:

    显示进程 33920 中所有类型的句柄及其计数:
    在cmd中,运行“handle64 -s -p 33920”

  4. 结果如下所示:

在此处输入图像描述

  1. 运行步骤3,多次获取4的结果,然后检查差异并抓取内存激增的结果
  1. In win10, download the tool "Handle" in
    https://learn.microsoft.com/en-us/sysinternals/downloads/handle,

  2. usage:

    handle [[-a] [-u] | [-c [-l] [-y]] | [-s]] [-p |> [name]

  3. example:

    to show all types of handles and their count in process 33920:
    in the cmd, run "handle64 -s -p 33920"

  4. the result looks like this:

enter image description here

  1. run step 3, get the 4's result multi-times, then check the diff and grab the memory-surging ones
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文