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 Usage Error

Memory Usage Error

Scheduled Pinned Locked Moved C / C++ / MFC
performancehelp
6 Posts 3 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.
  • A Offline
    A Offline
    Anu_Bala
    wrote on last edited by
    #1

    Hi, In my application for one child window,im having more than 100 pages.When page up and page down im moving coresponding next pages.BEfore getting next page, im destroying the previous page by using DestroyWindow. But when i see in the Task Manager,Perormance Tab,The PF usage shows for every page it increasing 0.01GB and in Physical Memory(K)-Available the number(ex:1571826)is getting reduced and soon one error is coming like "Out of memory,edit". Im pasting here my PageUp and Pagedown code:

    void CGraphView::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
    {
    if(nChar == 33 || nChar == 34)
    {
    short iTempPgNo = ((CMainFrame*)AfxGetMainWnd())->m_ngiSchPNo;
    if(nChar == 33)
    {
    iTempPgNo--;
    }
    else
    {
    iTempPgNo++;
    }
    if(iTempPgNo != m_ngiSchPNo)
    {
    CString sNo;
    if( gpGView[nCurrGrpView]->glg_animation[giSchPNo].m_hWnd )
    {
    gpGView[nCurrGrpView]->glg_animation[giSchPNo].DestroyWindow(); //Destroying previous page.
    giSchPNo = iTempPgNo; //assigning new page number to giSchPNo varible,im using this variable in OnDraw() to get new page.
    if(giSchPNo > giGraphicCnt)
    giSchPNo = giGraphicCnt;
    ((CMainFrame*)AfxGetMainWnd())->m_ngiSchPNo = giSchPNo;
    }
    }

    }
    CView::OnKeyDown(nChar, nRepCnt, nFlags);
    

    }

    Eventhough im using DestroyWindow(),why the memory is getting increased for each page down.

    Anu

    M M 2 Replies Last reply
    0
    • A Anu_Bala

      Hi, In my application for one child window,im having more than 100 pages.When page up and page down im moving coresponding next pages.BEfore getting next page, im destroying the previous page by using DestroyWindow. But when i see in the Task Manager,Perormance Tab,The PF usage shows for every page it increasing 0.01GB and in Physical Memory(K)-Available the number(ex:1571826)is getting reduced and soon one error is coming like "Out of memory,edit". Im pasting here my PageUp and Pagedown code:

      void CGraphView::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
      {
      if(nChar == 33 || nChar == 34)
      {
      short iTempPgNo = ((CMainFrame*)AfxGetMainWnd())->m_ngiSchPNo;
      if(nChar == 33)
      {
      iTempPgNo--;
      }
      else
      {
      iTempPgNo++;
      }
      if(iTempPgNo != m_ngiSchPNo)
      {
      CString sNo;
      if( gpGView[nCurrGrpView]->glg_animation[giSchPNo].m_hWnd )
      {
      gpGView[nCurrGrpView]->glg_animation[giSchPNo].DestroyWindow(); //Destroying previous page.
      giSchPNo = iTempPgNo; //assigning new page number to giSchPNo varible,im using this variable in OnDraw() to get new page.
      if(giSchPNo > giGraphicCnt)
      giSchPNo = giGraphicCnt;
      ((CMainFrame*)AfxGetMainWnd())->m_ngiSchPNo = giSchPNo;
      }
      }

      }
      CView::OnKeyDown(nChar, nRepCnt, nFlags);
      

      }

      Eventhough im using DestroyWindow(),why the memory is getting increased for each page down.

      Anu

      M Offline
      M Offline
      Mark Salsbery
      wrote on last edited by
      #2

      Only frame windows destroy their associated C++ object when DestroyWindow is called. With CWnd-derived windows only the Windows UI HWND is destroyed when DestroyWindow is called. Do you need to delete a CWnd object too or are you reusing them? Or are they frame windows?

      Mark Salsbery Microsoft MVP - Visual C++ :java:

      A 1 Reply Last reply
      0
      • M Mark Salsbery

        Only frame windows destroy their associated C++ object when DestroyWindow is called. With CWnd-derived windows only the Windows UI HWND is destroyed when DestroyWindow is called. Do you need to delete a CWnd object too or are you reusing them? Or are they frame windows?

        Mark Salsbery Microsoft MVP - Visual C++ :java:

        A Offline
        A Offline
        Anu_Bala
        wrote on last edited by
        #3

        CGraphView is one of the childframe, this class is using to show Graphics window.We are using one third party DLL to show the gaphcis page(glg_animation).

        Anu

        1 Reply Last reply
        0
        • A Anu_Bala

          Hi, In my application for one child window,im having more than 100 pages.When page up and page down im moving coresponding next pages.BEfore getting next page, im destroying the previous page by using DestroyWindow. But when i see in the Task Manager,Perormance Tab,The PF usage shows for every page it increasing 0.01GB and in Physical Memory(K)-Available the number(ex:1571826)is getting reduced and soon one error is coming like "Out of memory,edit". Im pasting here my PageUp and Pagedown code:

          void CGraphView::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
          {
          if(nChar == 33 || nChar == 34)
          {
          short iTempPgNo = ((CMainFrame*)AfxGetMainWnd())->m_ngiSchPNo;
          if(nChar == 33)
          {
          iTempPgNo--;
          }
          else
          {
          iTempPgNo++;
          }
          if(iTempPgNo != m_ngiSchPNo)
          {
          CString sNo;
          if( gpGView[nCurrGrpView]->glg_animation[giSchPNo].m_hWnd )
          {
          gpGView[nCurrGrpView]->glg_animation[giSchPNo].DestroyWindow(); //Destroying previous page.
          giSchPNo = iTempPgNo; //assigning new page number to giSchPNo varible,im using this variable in OnDraw() to get new page.
          if(giSchPNo > giGraphicCnt)
          giSchPNo = giGraphicCnt;
          ((CMainFrame*)AfxGetMainWnd())->m_ngiSchPNo = giSchPNo;
          }
          }

          }
          CView::OnKeyDown(nChar, nRepCnt, nFlags);
          

          }

          Eventhough im using DestroyWindow(),why the memory is getting increased for each page down.

          Anu

          M Offline
          M Offline
          Malli_S
          wrote on last edited by
          #4

          glg_animation[giSchPNo].DestroyWindow()

          after destroying this window, are you still using glg_animation[giSchPNo] object ? What if user visits this page again? Do you create glg_animation[giSchPNo] window? And it would be better if you post your paint event function too. Apart from this, I noticed that you are using an array to hold the number of pages and destroying each window after page is scrolled. This shows that you'll be holding one page in the memory, then why are you using an array? Instead, you can create the page objects dynamically.

          [Delegates]      [Virtual Desktop]      [Tray Me !]
          -Malli...! :rose:****

          A 1 Reply Last reply
          0
          • M Malli_S

            glg_animation[giSchPNo].DestroyWindow()

            after destroying this window, are you still using glg_animation[giSchPNo] object ? What if user visits this page again? Do you create glg_animation[giSchPNo] window? And it would be better if you post your paint event function too. Apart from this, I noticed that you are using an array to hold the number of pages and destroying each window after page is scrolled. This shows that you'll be holding one page in the memory, then why are you using an array? Instead, you can create the page objects dynamically.

            [Delegates]      [Virtual Desktop]      [Tray Me !]
            -Malli...! :rose:****

            A Offline
            A Offline
            Anu_Bala
            wrote on last edited by
            #5

            if( !glg_animation[giSchPNo].m_hWnd )
            {
            char pFileName[500];
            memset(pFileName,0,500);
            strcpy(pFileName,FName[giSchPNo]);
            glg_animation[m_ngiSchPNo].Create( pFileName,this);
            ..
            ...
            }

            In OnDraw() im doing like this.Initailly i store all 100 pages name in FName array. Im destroying this varaibles in OnDestroy() using delete operator when im closing the window.

            Anu

            M 1 Reply Last reply
            0
            • A Anu_Bala

              if( !glg_animation[giSchPNo].m_hWnd )
              {
              char pFileName[500];
              memset(pFileName,0,500);
              strcpy(pFileName,FName[giSchPNo]);
              glg_animation[m_ngiSchPNo].Create( pFileName,this);
              ..
              ...
              }

              In OnDraw() im doing like this.Initailly i store all 100 pages name in FName array. Im destroying this varaibles in OnDestroy() using delete operator when im closing the window.

              Anu

              M Offline
              M Offline
              Malli_S
              wrote on last edited by
              #6

              But calling the DistroyWindow isn't enough. Check whether the create() function is successful, or you may end up in creating the window every time you enter paint event which will run your app out to memory soon. Try using the single glg_animation instead of an array, as you're creating / deleting the pages dynamically. This will reduce your memory usage, as at a time only one object will be in use from an array.

              [Delegates]      [Virtual Desktop]      [Tray Me !]
              -Malli...! :rose:****

              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