为混合模式应用程序禁用并发 GC

发布于 2024-12-11 10:15:32 字数 643 浏览 0 评论 0原文

设置:我有一个非托管/本机 Win32 应用程序,我将代码注入其中。我的代码主要是托管的,用 C++/CLI 编写并编译为 DLL。我的加载器/注入器修补了应用程序的 crt0 启动代码(基本上将对入口点函数的调用交换为对 LoadLibrary 的调用)。在附加到主机进程时,DLL 将多个组件 DLL 加载到内存中(注入的 DLL 本身是用非托管代码编写的,只有组件 DLL 是托管程序集)并修补各个内存位置以充当组件 DLL 的接口。

现在我在组件 DLL 中的代码似乎触发了内存泄漏 [如 Proper Object 中所述在 C++/CLI 中的处理],我一直在考虑借助 .NET 内存分析器工具对其进行调试。不幸的是,我不寻常的环境阻碍了该工具的充分利用。尝试将探查器附加到进程会导致它报告已为该进程启用并发 GC,这会阻止它使用其内部 API 来跟踪引用等。

我尝试创建一个配置文件来禁用该 GC 模式,但它似乎没有效果 - 探查器继续显示错误消息(我假设这是因为主机应用程序主要是本机的,因此不会在启动时解析配置文件)。我也尝试修改 machine.config 文件,但没有成功。

是否还有其他方法可以强制禁用并发垃圾收集器?

The setup: I have a unmanaged/native Win32 application that I inject my code into. My code is primarily managed, written in C++/CLI and compiled as a DLL. My loader/injector patches the application's crt0 startup code (basically swaps the call to the entry point function with one to LoadLibrary). On attaching to the host process, the DLL loads several component DLLs into memory (the injected DLL itself is written in unmanaged code, only the component DLLs are managed assemblies) and patches various memory locations to act as interfaces to the component DLLs.

Now my code in the component DLLs seems to be triggering a memory leak [ as mentioned in Proper Object Disposal In C++/CLI ] and I've been looking into debugging it with the help of the .NET memory Profiler tool. Unfortunately, my unusual environment hinders the full use of the tool. Attempting to attach the profiler to the process causes it to report that concurrent GC has been enabled for the process, which prevents it from using its internal API to track references and such.

I've tried to create an config file to disable that mode of GC but it seems to have no effect - The profiler continues to display the error message (I'm assuming this is because the host app is primarily native and therefore doesn't parse the config file at startup). I've also tried modifying the machine.config file, in vain.

Would there be some other way to forcefully disable the concurrent garbage collector?

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

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

发布评论

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

评论(1

浴红衣 2024-12-18 10:15:32

已修复:我通过 CorBindToRuntimeEx() 使用适当的标志来强制 GC 的服务器模式。

Fixed: I forced the server mode of GC by using the appropriate flag with CorBindToRuntimeEx().

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