关于内存增长,今天又有发现:只要刷新页面,在windows任务管理器中的“页面错误增量”就会出现,并且“内存增量”也会产生,并且总是1个单位的“页面错误增量”对应4K的“内存增量。而且增长的内存不释放!!!
以上为VC的DEBUG环境中测试的结果,关闭程序,看不到任何内存泄漏。使用BChecker6.01进行检查好像它指出的不对。可能是什么原因啊。我该如何调试?
以上为VC的DEBUG环境中测试的结果,关闭程序,看不到任何内存泄漏。使用BChecker6.01进行检查好像它指出的不对。可能是什么原因啊。我该如何调试?
解决方案 »
- 为什么微软要让.net技术取代com/dcom/windows dna
- MFC 用ODBC链接SQL Server如何实现多表查询??
- MFC 请教怎样设置STATIC TEXT控件的字体大小和颜色
- windows下做P2P网络编程,有没有可以直接使用的组件或开源代码
- 如何使程序窗口不断的响应onpaint消息,即使最小化或者被别的窗口覆盖的情况
- 请教打开一个蓝牙串口的问题
- 关于PC上位机与单片机的并行通信的问题
- 想从cwnd派生一个类, 显示一个窗体,窗体上显示一幅图片,有一个文本框,不知道怎么做?
- 如何在Win2000下屏蔽所有系统热键?
- 驱动程序答疑
- Unicode的显示问题
- 没有用过VC人的提问,请解疑
pDC=GetDC(); ReleaseDC
CDC dcMemory; dcMemory.DeleteDC( );
CBitmap bitmap; bitmap.DeleteObject();并且每次我最小化界面,内存就会释放不少,基本能到正常水平
CreateDC -> DeleteDC
BeginPaint -> EndPaint不能乱用,另外创建的对象必须用DeleteObject删除
CreateDC -> DeleteDC
BeginPaint -> EndPaint不能乱用,另外创建的对象必须用DeleteObject删除我好像没有乱用啊,是哪个用错了吗?
有两处
1:
void CDlgTestInput::OnPaint()
{
CPaintDC dc(this); // device context for painting
// TODO: Add your message handler code here
DispLed();
// Do not call CDialog::OnPaint() for painting messages
}void CDlgTestInput::DispLed()
{
/////////////////添加指示灯////////////
int i,j,row=125, column=35;
CBitmap bitmap;
CDC dcMemory;
CDC *pDC;
pDC=GetDC(); for (i=0; i<8;i++)
{
for (j=0;j<4;j++)
{
if (m_chInputLed[i][j]==0)
bitmap.LoadBitmap(IDB_BITMAP_GRAYLED);
else if (m_chInputLed[i][j]==1)
bitmap.LoadBitmap(IDB_BITMAP_GREENLED);
else if (m_chInputLed[i][j]==2)
bitmap.LoadBitmap(IDB_BITMAP_REDLED);
else
bitmap.LoadBitmap(IDB_BITMAP_GRAYLED); dcMemory.CreateCompatibleDC(pDC);
dcMemory.SelectObject(&bitmap);
pDC->BitBlt(90+row*j,60+column*i,40,40,&dcMemory,0,0,SRCCOPY);
dcMemory.DeleteDC( );
bitmap.DeleteObject();
}
}
ReleaseDC(pDC);
}2:
void CDlgPic::OnPaint()
{
CPaintDC dc(this); // device context for painting
CRect rect;
GetClientRect(&rect);
CBitmap bmp;
bmp.LoadBitmap(IDB_BITMAP_MAIN);
BITMAP bmpInfo;
bmp.GetBitmap(&bmpInfo);
CDC dcMemory;
dcMemory.CreateCompatibleDC(&dc);
CBitmap *pOldBmp=dcMemory.SelectObject(&bmp);
StretchBlt(
dc,// handle to destination device context
0, // x-coordinate of upper-left corner of dest. rectangle
0, // y-coordinate of upper-left corner of dest. rectangle
rect.Width(), // width of destination rectangle
rect.Height(), // height of destination rectangle
dcMemory.m_hDC, // handle to source device context
0, // x-coordinate of upper-left corner of source rectangle
0, // y-coordinate of upper-left corner of source rectangle
bmpInfo.bmWidth, // width of source rectangle
bmpInfo.bmHeight, // height of source rectangle
SRCCOPY // raster operation code
);
//将设备还原
dcMemory.SelectObject(pOldBmp);
dcMemory.DeleteDC( );
bmp.DeleteObject();
// Do not call CDialog::OnPaint() for painting messages
}
1:只要刷新页面,在windows任务管理器中的“页面错误增量”就会出现,并且“内存增量”也会产生,并且总是1个单位的“页面错误增量”对应4K的“内存增量。而且增长的内存不释放!!!其中的句柄、线程、GDI都没有没有增加2:每次我最小化界面,内存就会释放不少,基本能到正常水平