关于内存增长,今天又有发现:只要刷新页面,在windows任务管理器中的“页面错误增量”就会出现,并且“内存增量”也会产生,并且总是1个单位的“页面错误增量”对应4K的“内存增量。而且增长的内存不释放!!!
以上为VC的DEBUG环境中测试的结果,关闭程序,看不到任何内存泄漏。使用BChecker6.01进行检查好像它指出的不对。可能是什么原因啊。我该如何调试?

解决方案 »

  1.   

    我也出现了相同的问题!椐我调查是我调用的那些系统函数造成的,比如说DeleteAllItems
      

  2.   

    我仔细的查了程序,所有的
    pDC=GetDC();   ReleaseDC
    CDC dcMemory;  dcMemory.DeleteDC( );
    CBitmap bitmap;  bitmap.DeleteObject();并且每次我最小化界面,内存就会释放不少,基本能到正常水平
      

  3.   

    GetDC -> ReleaseDC
    CreateDC -> DeleteDC
    BeginPaint -> EndPaint不能乱用,另外创建的对象必须用DeleteObject删除
      

  4.   

    GetDC -> ReleaseDC
    CreateDC -> DeleteDC
    BeginPaint -> EndPaint不能乱用,另外创建的对象必须用DeleteObject删除我好像没有乱用啊,是哪个用错了吗?
      

  5.   

    程序为基于FORM的单文档,里面有很多child对话框 。我的程序如下
    有两处
    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
    }
      

  6.   

    难道问题不是出在这里?请注意以下现象:
    1:只要刷新页面,在windows任务管理器中的“页面错误增量”就会出现,并且“内存增量”也会产生,并且总是1个单位的“页面错误增量”对应4K的“内存增量。而且增长的内存不释放!!!其中的句柄、线程、GDI都没有没有增加2:每次我最小化界面,内存就会释放不少,基本能到正常水平