<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

        Mixed-mode C++/CLI app not shutting down CLR correctly(混合模式 C++/CLI 应用程序未正确关闭 CLR)
        <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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Force JsonConvert.SerializeXmlNode to serialize node value as an Integer or a Boolean(强制 JsonConvert.SerializeXmlNode 将节点值序列化为整数或布尔值)
                  Using JSON to Serialize/Deserialize TimeSpan(使用 JSON 序列化/反序列化 TimeSpan)
                  Could not determine JSON object type for type quot;Classquot;(无法确定类型“Class的 JSON 对象类型.)
                  How to deserialize a JSONP response (preferably with JsonTextReader and not a string)?(如何反序列化 JSONP 响应(最好使用 JsonTextReader 而不是字符串)?)
                  how to de-serialize JSON data in which Timestamp it-self contains fields?(如何反序列化时间戳本身包含字段的JSON数据?)
                  JSON.Net custom contract serialization and Collections(JSON.Net 自定义合约序列化和集合)

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

                          <tbody id='aeWF7'></tbody>

                        <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>