我是否需要在CFont上调用DeleteObject

时间:2010-10-21 05:16:19

标签: mfc

我想知道,在下列情况下我是否需要调用DeleteObject?

CFont* oldFont = label.GetFont();
LOGFONT oldLogFont;
oldFont->GetLogFont(&oldLogFont);
oldLogFont.lfWeight = FW_BOLD;
CFont newFont;
newFont.CreateFontIndirectW(&oldLogFont);
label.SetFont(&newFont, true);
// Do I need to call oldFont->DeleteObject() or newFont->DeleteObject()?

感谢。

1 个答案:

答案 0 :(得分:3)

不,不。 MFC类是RAII类。当对象超出范围(即解构)时,对象将被适当删除。