VC++ 6.0中CArray中保存大量对象时内存无法释放的问题,请各位指点

weixin_38049216 2016-06-05 02:02:15
复现条件:
1、编译环境:VC++ 6.0
2、以release方式编译,全部使用默认的编译选项和参数,并且不使用调试器执行该应用程序
3、在数组中存放超过100万个对象
执行程序后,在我的电脑上,接近有85M的内存无法自动释放。
有哪位能够帮忙解释并解决这个问题吗?
btw:受限于历史项目代码,我的应用程序开发环境无法迁移到更新的VisualStudio开发环境,因此不要建议我升级。谢谢。


#include "afxtempl.h"

long int g_cCount = 0; // 记录构造函数调用次数
long int g_dCount = 0; // 记录析构函数调用次数

class CMyTest
{
public:
CString m_str;


CMyTest()
{
m_str = "test string";

g_cCount++;
}


~CMyTest()
{
g_dCount++;
}

};

typedef CArray<CMyTest,CMyTest&> CArrayTest;



void Test()
{
g_cCount = 0;
g_dCount = 0;

CArrayTest testArray;

int count = 1000000;
// 一百万个对象
for(int i =0;i < count; i++ )
{
CMyTest testObj;
testObj.m_str = "test string";

testArray.Add(testObj);
}

testArray.RemoveAll();
testArray.FreeExtra();
}

void CTestMemDlg::OnOK() 
{
Test();

CString strInfo;
strInfo.Format("Object construction: %d  destruction: %d \r\n",g_cCount,g_dCount);
AfxMessageBox("finish\r\n"+strInfo);
}
...全文
10 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复

476

社区成员

发帖
与我相关
我的任务
社区描述
其他技术讨论专区
其他 技术论坛(原bbs)
社区管理员
  • 其他技术讨论专区社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧