VS2010 reports false memory leaks for static classes in a DLL

前端 未结 5 925
清歌不尽
清歌不尽 2020-12-19 10:14

A follow-up question to Memory leaks when calling ITK from Visual Studio DLL

I refined the problem to the simplest example.

struct A
  {
  public:
           


        
5条回答
  •  再見小時候
    2020-12-19 10:52

    Any of following solves the problem.

    (1) Create a fake dependency of the DLL on MFC, or

    (2) Use the solution suggested by smerlin: add this code next to DllMain

    struct _DEBUG_STATE
      {
      _DEBUG_STATE() {}
      ~_DEBUG_STATE() { _CrtDumpMemoryLeaks(); }
      };
    
    #pragma init_seg(compiler)
    _DEBUG_STATE ds;
    

提交回复
热议问题