locked
Can the DEBUG_NEW use at Windows Store game ?

    Question

  • At win32, there is a DEBUG_NEW macro in the "crtdbg.h" for catch the memory leaks.

    It use like the follow:

    #ifdef _DEBUG #define new DEBUG_NEW #endif

    int* p = new int;


    The code only do the "new" but not "delete",

    so, when the program exit,the content below will be print to the "output" window.

    Detected memory leaks!
    Dumping objects ->
    c:\mydata\svn\g5dev.cn\platform\appproj\projects\windowsdesktop\lobby\lobby.cpp(45) : {69} normal block at 0x00676100, 4 bytes long.
     Data: <    > CD CD CD CD 
    Object dump complete.

    I want to know, can I continue use the function at "Windows Store game" env?

    or there is any new method to display the memory leaks report to the output window when the program exit?

    I found the native C++ is hard to find the memory leaks at Windows Store env,

    in the win32 is easy and automatic.


    • Edited by lihuipeng49 Friday, December 05, 2014 7:06 AM
    Friday, December 05, 2014 7:04 AM

Answers

  • I just know another way for detecting memory leak which is available for Window Store apps(C++), you can try:

    _CrtDumpMemoryLeaks

    • Marked as answer by lihuipeng49 Wednesday, December 10, 2014 5:36 AM
    Monday, December 08, 2014 2:13 AM

All replies

  • I just know another way for detecting memory leak which is available for Window Store apps(C++), you can try:

    _CrtDumpMemoryLeaks

    • Marked as answer by lihuipeng49 Wednesday, December 10, 2014 5:36 AM
    Monday, December 08, 2014 2:13 AM
  • SimpleSampleMain::SimpleSampleMain(const std::shared_ptr<DX::DeviceResources>& deviceResources) :
    	m_deviceResources(deviceResources)
    {
        m_sceneRenderer = std::unique_ptr<DirectXTK3DSceneRenderer>(new DirectXTK3DSceneRenderer(m_deviceResources));
    
    	m_deviceResources->RegisterDeviceNotify(this);
    
    #ifdef _DEBUG
    	_CrtSetDbgFlag(_CRTDBG_LEAK_CHECK_DF);
    	int* p = new int;
    
    	int n = _CrtDumpMemoryLeaks(); // it can work here
    #endif
    }
    
    SimpleSampleMain::~SimpleSampleMain()
    {
        m_deviceResources->RegisterDeviceNotify(nullptr);
    
    	int n = _CrtDumpMemoryLeaks(); // the break point can't stop here
    }

    Yes, I try this, it can work at the program running.

    but, I don't know why the break point can't stop at the '~SimpleSampleMain'.

    I try to 'suspend' or 'suspend and shutdown',

    but, the break point can't stop at the '~SimpleSampleMain' too.

    I want to know where is the first Destroy function I can use to call _CrtDumpMemoryLeaks in Windows Store game.


    The follow is my sln:
    • Edited by lihuipeng49 Monday, December 08, 2014 8:12 AM
    Monday, December 08, 2014 8:01 AM