<small id='EPJjU'></small><noframes id='EPJjU'>

      <i id='EPJjU'><tr id='EPJjU'><dt id='EPJjU'><q id='EPJjU'><span id='EPJjU'><b id='EPJjU'><form id='EPJjU'><ins id='EPJjU'></ins><ul id='EPJjU'></ul><sub id='EPJjU'></sub></form><legend id='EPJjU'></legend><bdo id='EPJjU'><pre id='EPJjU'><center id='EPJjU'></center></pre></bdo></b><th id='EPJjU'></th></span></q></dt></tr></i><div id='EPJjU'><tfoot id='EPJjU'></tfoot><dl id='EPJjU'><fieldset id='EPJjU'></fieldset></dl></div>

      1. <tfoot id='EPJjU'></tfoot><legend id='EPJjU'><style id='EPJjU'><dir id='EPJjU'><q id='EPJjU'></q></dir></style></legend>
        • <bdo id='EPJjU'></bdo><ul id='EPJjU'></ul>

        混合模式 C++/CLI 应用程序未正确关闭 CLR

        时间:2023-05-21
        <legend id='jn3a5'><style id='jn3a5'><dir id='jn3a5'><q id='jn3a5'></q></dir></style></legend>

      2. <small id='jn3a5'></small><noframes id='jn3a5'>

        <tfoot id='jn3a5'></tfoot>
          <bdo id='jn3a5'></bdo><ul id='jn3a5'></ul>
          <i id='jn3a5'><tr id='jn3a5'><dt id='jn3a5'><q id='jn3a5'><span id='jn3a5'><b id='jn3a5'><form id='jn3a5'><ins id='jn3a5'></ins><ul id='jn3a5'></ul><sub id='jn3a5'></sub></form><legend id='jn3a5'></legend><bdo id='jn3a5'><pre id='jn3a5'><center id='jn3a5'></center></pre></bdo></b><th id='jn3a5'></th></span></q></dt></tr></i><div id='jn3a5'><tfoot id='jn3a5'></tfoot><dl id='jn3a5'><fieldset id='jn3a5'></fieldset></dl></div>

                  <tbody id='jn3a5'></tbody>

                1. 本文介绍了混合模式 C++/CLI 应用程序未正确关闭 CLR的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  限时送ChatGPT账号..

                  我的混合模式 MFC 应用程序正在创建错误的内存泄漏,因为在 MFC dll 关闭之前 CRT 没有时间关闭.

                  My mixed-mode MFC application is creating false memory leaks because the CRT doesn't have time to shut down before the MFC dll is shut down.

                  我有一个非常简单的小应用程序可以显示问题:

                  I have a very simple little app that shows the problem:

                  #include <windows.h>
                  #include <iostream>
                  
                  struct LongTimeToDestroy
                  {
                    ~LongTimeToDestroy()
                    {
                      std::cout << "Will get called!" << std::endl;
                      Sleep(3000);
                      std::cout << "Won't get called!" << std::endl;
                    }
                  };
                  
                  LongTimeToDestroy gJamsUpTheCRT;
                  
                  int main()
                  {
                  }
                  

                  使用 cl.exe/clr test.cpp 编译.运行时,您会得到:

                  Compile with cl.exe /clr test.cpp. When run, you get:

                  Will get called!
                  

                  问题的症结在于:在 gJamsUpTheCRT 之前声明的任何静态/全局变量都不会被释放.例如,在我的例子中,MFC CWinApp 派生类没有被清理.

                  The crux of the problem is: any static/global variables that were declared before gJamsUpTheCRT will not be deallocated. For example, in my case the MFC CWinApp-derived class is not cleaned up.

                  这是预期的行为吗?我想让我的应用完全关闭.

                  Is this expected behaviour? I would like to allow my app to completely shut down.

                  谢谢,

                  推荐答案

                  这是预期的行为吗?

                  Is this expected behaviour?

                  是的,尽管您必须阅读 CLI 规范中的细则.它承诺在程序终止时调用托管对象的终结器.但需要注意的是,执行此操作的终结器线程需要两秒钟才能完成工作.如果需要更长的时间,则 CLR 会假定存在严重错误.就像在不会收到信号的同步对象上阻塞代码的常见诅咒一样.它通过中止终结器线程并允许程序终止来处理它.没有诊断.

                  Yes, although you have to read the fine print in the CLI spec. Which promises that finalizers on managed objects are called when the program terminates. But with the caveat that the finalizer thread that does this gets two seconds to get the job done. If it takes longer then the CLR assumes that there's something drastically wrong. Like the common curse of having code blocking on a synchronization object that isn't going to get signaled. Which it deals with by aborting the finalizer thread and allowing the program to terminate. No diagnostic.

                  你必须解决这个限制.

                  这篇关于混合模式 C++/CLI 应用程序未正确关闭 CLR的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:如何在 Windows 窗体应用程序中显示 MFC 控件? 下一篇:带有 COM 接口的 MFC Dll

                  相关文章

                  <tfoot id='aeWF7'></tfoot>

                  1. <legend id='aeWF7'><style id='aeWF7'><dir id='aeWF7'><q id='aeWF7'></q></dir></style></legend>
                    1. <i id='aeWF7'><tr id='aeWF7'><dt id='aeWF7'><q id='aeWF7'><span id='aeWF7'><b id='aeWF7'><form id='aeWF7'><ins id='aeWF7'></ins><ul id='aeWF7'></ul><sub id='aeWF7'></sub></form><legend id='aeWF7'></legend><bdo id='aeWF7'><pre id='aeWF7'><center id='aeWF7'></center></pre></bdo></b><th id='aeWF7'></th></span></q></dt></tr></i><div id='aeWF7'><tfoot id='aeWF7'></tfoot><dl id='aeWF7'><fieldset id='aeWF7'></fieldset></dl></div>
                    2. <small id='aeWF7'></small><noframes id='aeWF7'>

                      • <bdo id='aeWF7'></bdo><ul id='aeWF7'></ul>