您的位置:首页 > 其它

VS Memory leaks (RichEdit2.0) and Access violation

2016-07-19 16:05 501 查看
Summary

Memory leaks RichEdit20

Access violation

Reference Link

Summary

When develop on a Windows application, solved memory leaks issue on RichEdit2.0, and pointer access violation exception.

Memory leaks (RichEdit2.0)

It is very common to encounter memory leaks when using RichEdit2.0 in Visual Studio, as this RichEdit2.0 requires to be initialized. The error displays as below,

Detected memory leaks!
Dumping objects ->
f:\dd\vctools\vc7libs\ship\atlmfc\src\mfc\occmgr.cpp(195) : {335} normal block at 0x00FDAA00, 80 bytes long.
Data: <                > 01 00 00 00 00 00 00 00 FF FF FF FF 00 00 00 00
f:\dd\vctools\vc7libs\ship\atlmfc\src\mfc\occmgr.cpp(181) : {334} normal block at 0x032E1F88, 44 bytes long.
Data: <                > FF FF FF FF 00 00 00 00 00 00 00 00 00 00 00 00
Object dump complete.


So add the RichEdit2.0 initialize code as below,

//for RichEdit2.0
if (!AfxInitRichEdit2())
{
msg = _T("Error in RichEdit 2.0 initialization!");
MessageBox(NULL, msg, _T("Fatal"), MB_ICONSTOP|MB_OK);
}


Above code must be added before the Dialog Windows was showed, as below code,

CAPDURunDlg dlg;
m_pMainWnd = &dlg;
INT_PTR nResponse = dlg.DoModal();
if (nResponse == IDOK)
{
// TODO: Place code here to handle when the dialog is
//  dismissed with OK
}
else if (nResponse == IDCANCEL)
{
// TODO: Place code here to handle when the dialog is
//  dismissed with Cancel
}


This memory leak issue resolved.

Access violation

Encountered below issue unhandled exception issue when exit the application, it caused by additional destroyed the instances, i.e. I destroyed the instance twice when exit the application.

Unhandled exception at 0x78d2b4ec (mfc90ud.dll) in APDURun.exe: 0xC0000005: Access violation reading location 0xfeeefeee.


The CLogger was destroyed as below code when exit,

BOOL CAPDURunDlg::DestroyWindow()
{
// TODO: Add your specialized code here and/or call the base class
//CLogger::DestroyInstance();
return CDialog::DestroyWindow();
}


The same instance was also destroyed at below code,

int CAPDURunApp::ExitInstance()
{
// TODO: Add your specialized code here and/or call the base class
CLogger::DestroyInstance();
return CWinAppEx::ExitInstance();
}


Delete the instance destroy code at one of these two places, problem resolved.

Reference Link

1, fail-to-debug-the-program

2,0xC0000005: Access violation reading location 0x00000008
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息