2

私は Visual C++ 2010 で開発を行っており、"Visual Leak Detector" というライブラリを使用してメモリ リークをチェックしています。それから、説明も解決もできないものを見つけました。これが私のコードです:

ManageRenderListenerCommand::ManageRenderListenerCommand(string action):mAction(action){
}

void ManageRenderListenerCommand::execute(){
    //Do something with action
}

ヘッダー ファイルは次のとおりです。

class ManageRenderListenerCommand : public IOgreCommand{
private:
    string      mAction;
public:
    ManageRenderListenerCommand(string action);
    void execute();
};

更新:ここで呼び出されます:

void OgreMediator::onOgreChanged(AbstractOgreNegotiator* negotiator, NegotiatorEvent& negotiatorEvent){
    IOgreCommand* command = NULL;
    if(negotiatorEvent.matchEvent("addToViewport")){
        command = new AddToViewportCommand(mCameraManager, mSceneCreator, mEngine);
    }else if (negotiatorEvent.matchEvent("manageRenderListener")){
        command = new ManageRenderListenerCommand(negotiatorEvent.getMessage());
    }else if (negotiatorEvent.matchEvent("manageMouseCamera")){
        command = new ManageMouseCameraCommand(mCameraManager, mMouseManager->getLastEvent());
    }

    //Execute the created command
    if (command){
        command->execute();
        delete command;
    }
}

また、4 つのメモリ リークのスタックは非常に似ているため、そのうちの 1 つを次に示します。

---------- Block 163 at 0x023CEAE0: 8 bytes ----------
  Call Stack:
    c:\program files\microsoft visual studio 10.0\vc\include\xmemory (36): CataractSimulator.exe!std::_Allocate<std::_Container_proxy> + 0x15 bytes
    c:\program files\microsoft visual studio 10.0\vc\include\xmemory (187): CataractSimulator.exe!std::allocator<std::_Container_proxy>::allocate + 0xB bytes
    c:\program files\microsoft visual studio 10.0\vc\include\xstring (469): CataractSimulator.exe!std::_String_val<char,std::allocator<char> >::_String_val<char,std::allocator<char> > + 0xA bytes
    c:\program files\microsoft visual studio 10.0\vc\include\xstring (543): CataractSimulator.exe!std::basic_string<char,std::char_traits<char>,std::allocator<char> >::basic_string<char,std::char_traits<char>,std::allocator<char> > + 0x5F bytes
    c:\users\cps\desktop\surgery-sim\project\simulator\src\managerenderlistenercommand.cpp (10): CataractSimulator.exe!ManageRenderListenerCommand::ManageRenderListenerCommand
    c:\users\cps\desktop\surgery-sim\project\simulator\src\ogremediator.cpp (28): CataractSimulator.exe!OgreMediator::onOgreChanged + 0x53 bytes
    c:\users\cps\desktop\surgery-sim\project\simulator\src\abstractogrenegotiator.cpp (5): CataractSimulator.exe!AbstractOgreNegotiator::notifyMediator + 0x1C bytes
    c:\users\cps\desktop\surgery-sim\project\simulator\src\ogrerenderobserverregistry.cpp (37): CataractSimulator.exe!OgreRenderObserverRegistry::addListener + 0x15 bytes
    c:\users\cps\desktop\surgery-sim\project\simulator\src\ogremediator.cpp (73): CataractSimulator.exe!OgreMediator::addRenderListener
    c:\users\cps\desktop\surgery-sim\project\simulator\src\mousemanager.cpp (6): CataractSimulator.exe!MouseManager::startMouse
    c:\users\cps\desktop\surgery-sim\project\simulator\src\ogremediator.cpp (58): CataractSimulator.exe!OgreMediator::initFramework
    c:\users\cps\desktop\surgery-sim\project\simulator\src\simulatorapi.cpp (27): CataractSimulator.exe!SimulatorAPI::Facade::initFramework
    c:\users\cps\desktop\surgery-sim\project\simulator\src\simulatorapi.cpp (60): CataractSimulator.exe!SimulatorAPI::initFramework
    c:\users\cps\desktop\surgery-sim\project\simulator\src\loader.cpp (23): CataractSimulator.exe!Loader::Facade::initFramework + 0x16 bytes
    c:\users\cps\desktop\surgery-sim\project\simulator\src\loader.cpp (45): CataractSimulator.exe!Loader::go
    c:\users\cps\desktop\surgery-sim\project\cataractsimulator\src\cataractloader.cpp (5): CataractSimulator.exe!CataractLoader::go + 0x8 bytes
    c:\users\cps\desktop\surgery-sim\project\cataractsimulator\src\cataractloader.cpp (26): CataractSimulator.exe!main
    f:\dd\vctools\crt_bld\self_x86\crt\src\crtexe.c (555): CataractSimulator.exe!__tmainCRTStartup + 0x19 bytes
    f:\dd\vctools\crt_bld\self_x86\crt\src\crtexe.c (371): CataractSimulator.exe!mainCRTStartup
    0x7791ED6C (File and line number not available): kernel32.dll!BaseThreadInitThunk + 0x12 bytes
    0x77A1377B (File and line number not available): ntdll.dll!RtlInitializeExceptionChain + 0xEF bytes
    0x77A1374E (File and line number not available): ntdll.dll!RtlInitializeExceptionChain + 0xC2 bytes
  Data:
    14 4E 3D 02    00 00 00 00                                   .N=..... ........
4

1 に答える 1

3

IOgreCommand (または IOgreCommand の派生元のクラス) に仮想デストラクタがない場合、IOgreCommand から派生したクラスは、IOgreCommand ポインタを削除するときに呼び出されるデストラクタを持ちません。

于 2013-04-17T12:07:07.823 に答える