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. Deleting modeless property sheet

Deleting modeless property sheet

Scheduled Pinned Locked Moved C / C++ / MFC
questionperformance
6 Posts 2 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.
  • R Offline
    R Offline
    rwilmink
    wrote on last edited by
    #1

    Hi all, I have a modeless property sheet with three pages. The pages are deleted in PostNCDestroy. However, when a page has not been opened when the sheet is closed, PostNCDestroy for that page is not called, causing memory leaks. How do I solve this? Ronald

    D 1 Reply Last reply
    0
    • R rwilmink

      Hi all, I have a modeless property sheet with three pages. The pages are deleted in PostNCDestroy. However, when a page has not been opened when the sheet is closed, PostNCDestroy for that page is not called, causing memory leaks. How do I solve this? Ronald

      D Offline
      D Offline
      David Crow
      wrote on last edited by
      #2

      rwilmink wrote: ...causing memory leaks. Where? If the page has not been created, it will not have allocated any memory. Is the leak in the property sheet?


      "One must learn from the bite of the fire to leave it alone." - Native American Proverb

      R 1 Reply Last reply
      0
      • D David Crow

        rwilmink wrote: ...causing memory leaks. Where? If the page has not been created, it will not have allocated any memory. Is the leak in the property sheet?


        "One must learn from the bite of the fire to leave it alone." - Native American Proverb

        R Offline
        R Offline
        rwilmink
        wrote on last edited by
        #3

        The pages are first created on the heap and then added to the sheet (sheet->AddPage(pPage)). I delete the sheet and the pages with 'delete this' in PostNCDestroy. When a page has not been openened (by clicking the tab) PostNCDestroy is not called so the page is not deleted from the heap.

        D 1 Reply Last reply
        0
        • R rwilmink

          The pages are first created on the heap and then added to the sheet (sheet->AddPage(pPage)). I delete the sheet and the pages with 'delete this' in PostNCDestroy. When a page has not been openened (by clicking the tab) PostNCDestroy is not called so the page is not deleted from the heap.

          D Offline
          D Offline
          David Crow
          wrote on last edited by
          #4

          rwilmink wrote: The pages are first created on the heap... Why? Can you not just use something like:

          class MySheet : CPropertySheet
          {
          CMyPage page1;
          CMyPage page2;
          CMyPage page3;
          };

          MySheet::MySheet()
          {
          AddPage(&page1);
          AddPage(&page1);
          AddPage(&page1);
          }

          No heap and no memory allocation/cleanup to mess with.


          "One must learn from the bite of the fire to leave it alone." - Native American Proverb

          R 1 Reply Last reply
          0
          • D David Crow

            rwilmink wrote: The pages are first created on the heap... Why? Can you not just use something like:

            class MySheet : CPropertySheet
            {
            CMyPage page1;
            CMyPage page2;
            CMyPage page3;
            };

            MySheet::MySheet()
            {
            AddPage(&page1);
            AddPage(&page1);
            AddPage(&page1);
            }

            No heap and no memory allocation/cleanup to mess with.


            "One must learn from the bite of the fire to leave it alone." - Native American Proverb

            R Offline
            R Offline
            rwilmink
            wrote on last edited by
            #5

            No, I can't, all kinds of problems with cyclic includes.

            D 1 Reply Last reply
            0
            • R rwilmink

              No, I can't, all kinds of problems with cyclic includes.

              D Offline
              D Offline
              David Crow
              wrote on last edited by
              #6

              Ok, then if the property sheet is allocating memory for the pages, it should also free up that memory. Something like:

              class MySheet : public CPropertySheet
              {
              MyPage *page1;
              MyPage *page2;
              MyPage *page3;
              };

              MySheet::MySheet()
              {
              page1 = new MyPage;
              AddPage(page1);
              page2 = new MyPage;
              AddPage(page2);
              page3 = new MyPage;
              AddPage(page3);
              }

              MySheet::~MySheet()
              {
              delete page1;
              delete page2;
              delete page3;
              }

              BOOL MySheet::OnCommand( WPARAM wParam, LPARAM lParam )
              {
              WORD wNotifyCode,
              wId;

              wId         = LOWORD(wParam);
              wNotifyCode = HIWORD(wParam);
              
              if (BN\_CLICKED == wNotifyCode)
              {
                  if (IDOK == wId)
                  {
                      if (! ProcOk())
                          return TRUE;
                  }
              }
              
              return CPropertySheet::OnCommand(wParam, lParam);
              

              }

              // the OK button was clicked
              BOOL MySheet::ProcOk( void )
              {
              if (::IsWindow(page1->m_hWnd))
              {
              if (! page1->OnKillActive())
              return FALSE;
              }

              if (::IsWindow(page1->m\_hWnd))
                  page1->OnOK();
              
              return TRUE;
              

              }

              void MyPage::OnOK()
              {
              // the sheet is about to go away.
              // do any page-specific cleanup here

              CPropertyPage::OnOK();
              

              }

              BOOL MyPage::OnKillActive()
              {
              // the page is being changed.
              // do any page-specific validation here.
              // return 0 if the page should not change

              return CPropertyPage::OnKillActive();
              

              }


              "One must learn from the bite of the fire to leave it alone." - Native American Proverb

              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