我需要在CFont上调用DeleteObject吗

Che*_*eng 6 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()?
Run Code Online (Sandbox Code Playgroud)

谢谢。

Goz*_*Goz 5

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