0

这是我的 WinMain 方法的摘录。它并不完整,但我认为足以说明问题的核心。请不要问我为什么要自动删除数据模块。这完全是另一个问题(与应用程序初始化过早结束并在一个构造函数中出现异常时不正确的完成顺序有关)。

extern PACKAGE TDataModule_Local *DataModule_Local;

class TDataModule_Local :
   public TDataModule
{
...
public:
   __fastcall        TDataModule_Local(TComponent *Owner);
   __fastcall        ~TDataModule_Local();
}

WINAPI wWinMain(HINSTANCE, HINSTANCE, LPTSTR, int)
{
    Application->Initialize();
    Application->CreateForm(__classid(TMainForm), &MainForm);
    Application->CreateForm(__classid(TDataModule_Local), &DataModule_Local);    
    Application->Run();    

    if (DataModule_Local != NULL)
    {
       delete DataModule_Local;     // destructor not called! why?
       DataModule_Local = NULL;
    }

    return 0;    
}

当我使用删除运算符时,不会调用数据模块的奇怪析构函数。Is 在程序到达 WinMain 方法的大括号后调用:

在此处输入图像描述

4

1 回答 1

1

You said

deleting data module explicitly when it should be done automatically

Obviously whatever code is designed to free it automatically is still trying to do so, blissfully ignorant of your problems with finalization order.

Just because you've set your pointer to NULL doesn't mean that there isn't a copy of the pointer sitting in a list of objects to be cleaned up on exit.

于 2012-12-07T14:29:18.780 回答