{"id":3942,"date":"2014-03-30T06:27:55","date_gmt":"2014-03-30T06:27:55","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2014\/03\/30\/destroywindow-in-ondestroy-not-working-collection-of-common-programming-errors\/"},"modified":"2014-03-30T06:27:55","modified_gmt":"2014-03-30T06:27:55","slug":"destroywindow-in-ondestroy-not-working-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2014\/03\/30\/destroywindow-in-ondestroy-not-working-collection-of-common-programming-errors\/","title":{"rendered":"DestroyWindow in OnDestroy not working-Collection of common programming errors"},"content":{"rendered":"<p>Hi I&#8217;m making a dialog based application in MFC using:<\/p>\n<pre><code>BOOL CClockMasterDlg::OnInitDialog()\n{\nCDialogEx::OnInitDialog();\n\nm_ModeTabs.Create(this,WS_CHILD | WS_VISIBLE, 0);\n}\n<\/code><\/pre>\n<p>If I destroy <code>m_ModeTabs<\/code> in <code>CClockMasterDlg::OnInitDialog<\/code> function after it is created using :<\/p>\n<pre><code>m_ModeTabs.DestroyWindow();\n<\/code><\/pre>\n<p>I get no memory but leaks when I place it in <code>CClockMasterDlg::OnDestroy()<\/code> I get memory leaks, even tough it gets called and returns <code>true<\/code>. I don&#8217;t believe that <code>OnDestroy<\/code> is <code>OnInitDialog<\/code>&#8216;s contrary, but then which function is? There is no <code>OnExitDialog<\/code>.<\/p>\n<p>Detected memory leaks! Dumping objects -&gt; {601} client block at <code>0x00AEED48<\/code>, subtype c0, 212 bytes long. a <code>CMFCVisualManager<\/code> object at <code>$00AEED48<\/code>, 212 bytes long Object dump complete. The program <code>[5312] ClockMaster.exe: Native<\/code> has exited with code 2 (0x2).<\/p>\n<p>Even tough the window should be destroyed automatically since it`s not a pointer I still shouldn&#8217;t get memory leaks should I? And since placing<\/p>\n<pre><code>m_ModeTabs.DestroyWindow();\n<\/code><\/pre>\n<p>in the <code>OnInitDialog<\/code> function after its created solves the memory leak it cant really be something else causing the trouble can it? Removing the <code>m_ModeTabs.Create(...<\/code> Also solves the memory leak so I&#8217;m quite certain that its <code>m_ModeTabs<\/code> causing it.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Hi I&#8217;m making a dialog based application in MFC using: BOOL CClockMasterDlg::OnInitDialog() { CDialogEx::OnInitDialog(); m_ModeTabs.Create(this,WS_CHILD | WS_VISIBLE, 0); } If I destroy m_ModeTabs in CClockMasterDlg::OnInitDialog function after it is created using : m_ModeTabs.DestroyWindow(); I get no memory but leaks when I place it in CClockMasterDlg::OnDestroy() I get memory leaks, even tough it gets called and [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-3942","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/3942","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=3942"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/3942\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=3942"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=3942"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=3942"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}