Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Memory Leak!

Memory Leak!

Scheduled Pinned Locked Moved C / C++ / MFC
performancehelpquestion
4 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • W Offline
    W Offline
    wilche
    wrote on last edited by
    #1

    hello everybody! I have some trouble in freeing up the memory allocated for dialog items. I have created the Gui screens using new and I use DestroyScreen to free my memory like this: virtual void DestroyScreen(void) { if (m_pDlg->GetSafeHwnd()) { delete m_pDlg; m_pDlg = NULL; } } } I go through each dlg using this DestroyScreen function. The returned warning is: Warning: calling DestroyWindow in CDialog::~CDialog -- OnDestroy or PostNcDestroy in derived class will not be called. Detected memory leaks! Dumping objects -> {3539} client block at 0x0081A330, subtype 0, 332 bytes long. a CDialog object at $0081A330, 332 bytes long Could anyone please help me with this one? Thanks everyone! Cheers, wilche

    N M I 3 Replies Last reply
    0
    • W wilche

      hello everybody! I have some trouble in freeing up the memory allocated for dialog items. I have created the Gui screens using new and I use DestroyScreen to free my memory like this: virtual void DestroyScreen(void) { if (m_pDlg->GetSafeHwnd()) { delete m_pDlg; m_pDlg = NULL; } } } I go through each dlg using this DestroyScreen function. The returned warning is: Warning: calling DestroyWindow in CDialog::~CDialog -- OnDestroy or PostNcDestroy in derived class will not be called. Detected memory leaks! Dumping objects -> {3539} client block at 0x0081A330, subtype 0, 332 bytes long. a CDialog object at $0081A330, 332 bytes long Could anyone please help me with this one? Thanks everyone! Cheers, wilche

      N Offline
      N Offline
      Nish Nishant
      wrote on last edited by
      #2

      The right way to do this is to delete it in the PostNcDestroy

      void CYourDlg::PostNcDestroy()
      {
      CDialog::PostNcDestroy();
      delete this;
      }

      Regards, Nish


      Author of the romantic comedy Summer Love and Some more Cricket [New Win] Review by Shog9 Click here for review[NW]

      1 Reply Last reply
      0
      • W wilche

        hello everybody! I have some trouble in freeing up the memory allocated for dialog items. I have created the Gui screens using new and I use DestroyScreen to free my memory like this: virtual void DestroyScreen(void) { if (m_pDlg->GetSafeHwnd()) { delete m_pDlg; m_pDlg = NULL; } } } I go through each dlg using this DestroyScreen function. The returned warning is: Warning: calling DestroyWindow in CDialog::~CDialog -- OnDestroy or PostNcDestroy in derived class will not be called. Detected memory leaks! Dumping objects -> {3539} client block at 0x0081A330, subtype 0, 332 bytes long. a CDialog object at $0081A330, 332 bytes long Could anyone please help me with this one? Thanks everyone! Cheers, wilche

        M Offline
        M Offline
        Michael Dunn
        wrote on last edited by
        #3

        You're destroying the dialog C++ object before the dialog window has been destroyed. Call m_pDlg->DestroyWindow() (assuming these are modeless) and call delete this; in each dialog's PostNCDestroy(). --Mike-- Just released - RightClick-Encrypt v1.3 - Adds fast & easy file encryption to Explorer My really out-of-date homepage Sonork-100.19012 Acid_Helm

        1 Reply Last reply
        0
        • W wilche

          hello everybody! I have some trouble in freeing up the memory allocated for dialog items. I have created the Gui screens using new and I use DestroyScreen to free my memory like this: virtual void DestroyScreen(void) { if (m_pDlg->GetSafeHwnd()) { delete m_pDlg; m_pDlg = NULL; } } } I go through each dlg using this DestroyScreen function. The returned warning is: Warning: calling DestroyWindow in CDialog::~CDialog -- OnDestroy or PostNcDestroy in derived class will not be called. Detected memory leaks! Dumping objects -> {3539} client block at 0x0081A330, subtype 0, 332 bytes long. a CDialog object at $0081A330, 332 bytes long Could anyone please help me with this one? Thanks everyone! Cheers, wilche

          I Offline
          I Offline
          includeh10
          wrote on last edited by
          #4

          let me guess ur problem: m_pDlg is a pointer to CDialog or its sub-class, say XDialog. instances are not from XDialog, but its sub-class. if my guess is correct, simply change distructor to 'virtual' one. that is all. for MFC class, it is not necessary to call Destroy, MFC can do it itself. includeh10

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups