Memory Usage Error
-
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
-
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
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:
-
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:
-
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
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:**** -
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:****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
-
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
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:****