是否可以通过使用 AfxFreeLibrary 卸载非托管库来减少托管应用程序的工作集?

发布于 2024-07-06 17:06:32 字数 290 浏览 7 评论 0原文

我有一个托管 Windows 应用程序,它加载托管 C++ 组件,该组件使用 AfxLoadLibrary 加载第三方组件(如果客户端计算机上存在)。 一旦检测到,我将使用 AfxFreeLibrary 卸载该组件,以尝试降低托管父应用程序的工作集。

对 AfxFreeLibrary 的调用成功(使用 Process Explorer 验证),但没有释放任何内存。 这是由于托管应用程序的性质所致,还是有办法释放此进程空间?

我并不是在寻找替代方法来解决这个问题,因为代码已经在生产中,而是我想知道卸载方法是否值得。

I have a managed Windows application that loads a managed C++ component that uses AfxLoadLibrary to load a third party component if present on the client machine. Once detected, I'm unloading the component using AfxFreeLibrary in an attempt to lower the working set of the managed parent application.

The call to AfxFreeLibrary is successful (verified using Process Explorer), but no memory is freed up. Is this due to the nature of a managed application, or is there a way to free up this process space?

I'm not looking for alternative ways to tackle this problem in general, since the code is already in production, rather I would like to find out if the approach of unloading is worthwhile.

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

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

发布评论

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

评论(1

-柠檬树下少年和吉他 2024-07-13 17:06:32

应该可以,您可以通过编写纯本机应用程序并查看工作集来证明这一点。
但是,工作集是运行应用程序所需的内存大小,因此如果 dll 使用的代码可以被换出,那么工作集不会减少 - Windows 不会将其算作工作集的一部分。

如果 dll 具有分配给进程的私有内存,但无法交换,那么这确实很重要,并且会减少工作集。

所以答案是视情况而定。 它不能保证产生任何影响,如果不使用该 dll,那么它将被换出并且不属于当前工作集。 你最好不要费心卸载它,除非你想保持东西整洁。

减少工作集的唯一方法是让您的应用程序使用更少的内存。 由于它是一个 .NET 应用程序,您可能根本无法控制它(因为 GC 将自行决定工作集中有多少内存是“活动的”和需要的)

It should do, you can prove it by writing a pure native app and seeing the working set.
However, working set is the size of the memory required to run the app, so if the code used by the dll can be swapped out, then the working set will not be reduced - Windows doesn't count it as part of the working set.

If the dll has private memory allocated to the process, that cannot be swapped, then that does count and will reduce the working set.

so the answer is that it depends. Its not guaranteed to make any difference, and if the dll is not used, then it will have been swapped out and isn't part of the current working set. You might as well not bother unloading it, unless you like to keep things tidy.

The only way to reduce the working set is to have your app use less memory. As its a .NET app, chances are you don't have much control over it at all (as the GC will make its own mind up about how much memory is 'active' and needed in the working set)

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