经过查找,发现是系统有资源没有释放,下面是有问题的代码,但是我不知道怎么 去释放,清 帮忙
int CDecoBitMap::Create()
{
CImageList imlSymbols;
CImageList imlDecoSpecial;
CImageList imlDecoCond;
CImageList imlDecoValu;
CImageList imlDecoNode;
HIMAGELIST hResult1;
HIMAGELIST hResult2;
HIMAGELIST hResult3;
int iSym, iDeco, iCond;
int iNode;
int cnt;
// ImageList aus den Basissymbolen und den Decorationen erzeugen
m_imageList.Create(20, 16, TRUE, 100, 100);
imlSymbols.Create(IDB_SYMBOLS, 20, 0, RGB(255, 255, 255));
imlDecoSpecial.Create(IDB_DECO_SPECIAL, 20, 0, RGB(255, 255, 255));
imlDecoCond.Create(IDB_DECO_COND, 20, 0, RGB(255, 255, 255));
imlDecoValu.Create(IDB_DECO_VALU, 20, 0, RGB(255, 255, 255));
imlDecoNode.Create(IDB_DECO_NODE, 20, 0, RGB(255, 255, 255));
m_nSymbols = imlSymbols.GetImageCount();
m_nDecoSpecial = imlDecoSpecial.GetImageCount();
m_nDecoValue = imlDecoValu.GetImageCount();
m_nDecoCond = imlDecoCond.GetImageCount();
m_nDecoNode = imlDecoNode.GetImageCount();
m_nDecoIcons = m_nDecoSpecial + m_nDecoValue * m_nDecoCond * m_nDecoNode;
cnt = 0;
for (iSym=0; iSym<m_nSymbols; iSym++)
{
// Symbol mit den Spezialdekorationen mischen
for (iDeco=0; iDeco<m_nDecoSpecial; iDeco++)
{
hResult1 = ImageList_Merge(imlSymbols, iSym,
imlDecoSpecial, iDeco, 0, 0);
m_imageList.Add(ImageList_ExtractIcon(0, hResult1, 0));
cnt++;
DestroyIcon(ImageList_ExtractIcon(0,hResult1,0)); // 没有起作用
ImageList_Destroy(hResult1);
}
// Symbol mit den Bedingungs- und Bewertungsdekorationen mischen
for (iDeco=0; iDeco<m_nDecoValue; iDeco++)
{
hResult1 = ImageList_Merge(imlSymbols, iSym, imlDecoValu, iDeco, 0, 0);
for (iCond=0; iCond<m_nDecoCond; iCond++)
{
hResult2 = ImageList_Merge(hResult1, 0, imlDecoCond, iCond, 0, 0);
for (iNode = 0; iNode<m_nDecoNode; iNode++)
{
hResult3 = ImageList_Merge(hResult2, 0, imlDecoNode, iNode, 0, 0);
m_imageList.Add(ImageList_ExtractIcon(0, hResult3, 0));
cnt++;
DestroyIcon(ImageList_ExtractIcon(0,hResult1,0)); //没有起作用
ImageList_Destroy(hResult3);
}
m_imageList.Add(ImageList_ExtractIcon(0, hResult2, 0));
cnt++;
ImageList_Destroy(hResult2);
}
ImageList_Destroy(hResult1);
}
}
return cnt == m_nDecoIcons * m_nSymbols;
}
我在任务管理器中查看 系统gdi objects and uer obejct handles counts go up by 2. 增长2倍
清问怎么释放阿
5 个解决方案
#1
delete 试试
#2
gdi 对象需要调用DeleteObject api
#3
通过GC回收
#4
mark+ding
#5
the question can be fixed after adding a temp variable for ImageList_ExtractIco(),then destroy it
HICON hIcon = ImageList_ExtractIcon(0,hResult2,0);
m_imageList.Add(hIcon);
DestroyIcon(hIcon);
cnt++;
ImageList_Destroy(hResult2);
#1
delete 试试
#2
gdi 对象需要调用DeleteObject api
#3
通过GC回收
#4
mark+ding
#5
the question can be fixed after adding a temp variable for ImageList_ExtractIco(),then destroy it
HICON hIcon = ImageList_ExtractIcon(0,hResult2,0);
m_imageList.Add(hIcon);
DestroyIcon(hIcon);
cnt++;
ImageList_Destroy(hResult2);