// Creates a new grid cell and performs any necessary initialisation
CGridCell* CGridCtrl::CreateCell(int nRow, int nCol)
{
    CGridCell* pCell = new CGridCell;
    if (!pCell)
        return NULL;
    
    // Make format same as cell above
    if (nRow > 0 && nCol >= 0 && nCol < m_nCols)
        pCell->nFormat = GetItemFormat(nRow-1, nCol);
 
    // Make font default grid font
    memcpy(&(pCell->lfFont), &m_Logfont, sizeof(LOGFONT));
    
    return pCell;
}编译器提示该处发生了内存泄漏,请问有人用过吗?如何解决???多谢!!

解决方案 »

  1.   

    这是因为你调用CreateCell返回CGridCell指针后,你没有释放这个指针造成的。编译器提示的泄漏会指向被泄漏的指针的产生处。所以指到了这个函数中。
       CGridCell* pCell = new CGridCell;创建了新的CGridCell指针,它并不在本函数中被释放,因此你必须自己调用delete pCell才能解决这个泄漏问题。
    比如CGridCell *pCell = m_GridCtrl.CreateCell();
    delete pCell;
    这样才能释放掉
      

  2.   

    使用CreateCell的客户代码必须负责删除。
      

  3.   

    你在什么地方对CGridCell* pCell = new CGridCell;这个new出来的指针进行删除了?不删除的话就会内存泄漏。
      

  4.   

    楼上的可能都没有用过 CGridCtrl吧CreateCell时 new的内存并不是一定要在本过程释放的CGridCtrl中有两个链表, 一个储存行, 一个储存列Cell代表其中的一个单元格, CreateCell出来后, new 的内存被加入到这两个链表中对象删除时, 会统一清除分配的内存之所以发生内存泄露, 可能是楼主不小心更改了它的代码, 或是下载了别人更改过的版本http://www.codeproject.com  
    进入后, 搜索 CGridCtrl
      

  5.   

    哈哈,俺下载了别人一个从CGridCtrl中派生出来的版本,它可以使用Combo Box。
    有没有版本可以实现类似功能的?
      

  6.   

    我前段时间从 codeproject 中下载的版本combo box, edit, 日历 等都有了其实再自已扩充也很简单的