如何找到我的 .Net 应用程序泄漏 Windows 句柄的位置?

发布于 2024-07-07 10:04:49 字数 518 浏览 8 评论 0原文

我有一个 WinForms .Net 应用程序,它运行大量 XPS 文档(数千个),在此运行期间,每个文档的句柄数量(根据 sysinternals 进程监视器和任务管理器)增加 3-10 个。 我严重怀疑这些句柄是由 MS .Net XPS 框架库打开而不是关闭的,但我无法追踪它。

尽管单步执行代码,但在同一运行期间,句柄计数会在不同点增加。 例如,一次通过循环,句柄计数将在一行上跳跃 1,而下一次可能不会,或者可能跳跃 2。所以我怀疑 XPS com 组件存在句柄泄漏。

虽然内存使用情况很好,但如果我继续像这样耗尽句柄,那么我会让应用程序崩溃,也许桌面也会崩溃。

到目前为止,我已尝试使用 sysinternals 进程资源管理器来查看句柄,但它们都被标记为没有更多详细信息。 还使用了 sysinternals 中的handle.exe,这在快照之前、期间和之后没有显示出任何显着差异。

关于如何追踪手柄去向的任何线索? 我想我必须简化为单线程控制台应用程序来测试。

问候

瑞安

I've got a WinForms .Net app that runs over a lot of XPS documents (thousands) and during this run the number of handles (according sysinternals process monitor and task manager) increases by between 3-10 for each document. I heavily suspect that these are handles that are opened and not closed by the MS .Net XPS framework libraries but I can't track it down.

Despite stepping through the code the handle count increases at different points during the same run. For example, one pass through the loop and the handle count will jump by 1 on one line and next time it might not, or it might jump by 2. So I suspect the XPS com components have a handle leak.

Memory use is fine though, but if I keep exhausting handles like this then I'll crash the app and maybe the desktop.

So far I have tried sysinternals process explorer to look at the handles but they are all marked as with no more detail. Also used handle.exe from sysinternals and this does not show any significant different between a before, during and after snapshot.

Any clues on how to track down where the handles are going? I think I'm going to have to simplify to a single threaded console app to test.

Regards

Ryan

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

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

发布评论

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

评论(4

深海里的那抹蓝 2024-07-14 10:04:49

虽然单独使用有点贵,但我们使用 ANTS Profiler 和对于发现此类问题非常有帮助。 您可以下载并尝试试用版。

可能还有其他好的分析器,但这是我熟悉的一个。

Although it's a bit expensive for singular use, we use ANTS Profiler and it is quite helpful in finding issues like this. You could download and try the trial version.

There are probably other good profilers out there as well, but this is the one that I am familiar with.

梦罢 2024-07-14 10:04:49

可能很愚蠢,但是您是否检查过您是否正在处理所有一次性物品?

Possibly stupid, but have you checked that you're disposing everything that's disposable?

梦里南柯 2024-07-14 10:04:49

那么,您是否忘记从 PackageStore 中删除您创建的 XPS 文档? 那么用于支持您的包的任何 MemoryStreams 又如何呢?

So, did you forget to remove the XPS Documents you've created form the PackageStore? And what about any MemoryStreams used to back your Packages?

缺⑴份安定 2024-07-14 10:04:49

我在使用 YourKit .net profiler 准确诊断此类故障方面拥有良好的经验。 强烈推荐 - 它相对便宜,甚至可以很好地处理 C++-CLI(我尝试过其他的,例如 dottrace jetbrains要么拒绝要么直接崩溃)。

I've had good experiences diagnosing exactly this kind of fault using YourKit .net profiler. Highly recommended - it's relatively cheap and it even copes with C++-CLI reasonably well (I've tried others such as dottrace from jetbrains which either refused or just crashed outright).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文