VS Memory leaks (RichEdit2.0) and Access violation

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.

1, fail-to-debug-the-program
2,0xC0000005: Access violation reading location 0x00000008


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值