妈了个逼, 这段简单的STL都内存泄露了?哪出问题了?

lin_style 2007-05-30 08:57:32
#define _CRTDBG_MAP_ALLOC
#include <crtdbg.h>
#include <vector>

using namespace std;


int main()
{

int iarr[]={3,2,5,6,33,4,1,9};

vector<int> arr(iarr, iarr+sizeof(iarr)/sizeof(*iarr));

system("pause");
_CrtDumpMemoryLeaks();
return 0;

}




调试信息如下
VC03

Detected memory leaks!
Dumping objects ->
{53} normal block at 0x00372F20, 32 bytes long.
Data: < > 01 00 00 00 02 00 00 00 03 00 00 00 04 00 00 00
Object dump complete.
...全文
493 13 打赏 收藏 转发到动态 举报
写回复
用AI写文章
13 条回复
切换为时间正序
请发表友善的回复…
发表回复
Wolf0403 2007-05-31
  • 打赏
  • 举报
回复
linux -> Valgrind
walkingstick 2007-05-31
  • 打赏
  • 举报
回复
mark~~~
lin_style 2007-05-30
  • 打赏
  • 举报
回复
。。face居然在论坛上。。。。。。

那如果要查内存泄露,在代码中嵌入代码就不太实际了
大家都用什么工具测的呢
foochow 2007-05-30
  • 打赏
  • 举报
回复
你直接在main函数开始的时候加上这个就可以
_CrtSetDbgFlag(_CrtSetDbgFlag(_CRTDBG_REPORT_FLAG) | _CRTDBG_LEAK_CHECK_DF);
foochow 2007-05-30
  • 打赏
  • 举报
回复
int main()
{
int iarr[]={3,2,5,6,33,4,1,9};
{
vector<int> arr(iarr, iarr+sizeof(iarr)/sizeof(*iarr));
system("pause");
}
_CrtDumpMemoryLeaks();
return 0;
}
foochow 2007-05-30
  • 打赏
  • 举报
回复
诶,不要转牛角尖哦。。_CrtDumpMemoryLeaks();表示的是当前的内存泄漏情况,在你调用这个函数的时候任何这个时刻没有被释放的内存,它都会当做内存泄漏。。
fflush 2007-05-30
  • 打赏
  • 举报
回复
以前的某个帖子里讨论过类似的问题(当然,那个帖子里大部分人都没搞清为什么,但是他们都以为自己搞清了。。。)

#define _CRTDBG_MAP_ALLOC
#include <crtdbg.h>
#include <vector>

using namespace std;


int main()
{

int iarr[]={3,2,5,6,33,4,1,9};

vector<int> arr(iarr, iarr+sizeof(iarr)/sizeof(*iarr));

system("pause");
_CrtDumpMemoryLeaks();
return 0;//这里arr才会析构,内存才会被释放!!

}
lin_style 2007-05-30
  • 打赏
  • 举报
回复
taodm((不能收CSDN社区短信息,请莫浪费精力)) ( ) 信誉:100 Blog 加为好友 2007-05-30 21:24:04 得分: 0


看《STL源码剖析》,关于stl内存管理的章。原因里面都写着呢。



//..能否现在说明一下,偶知道你的是STL高手。 。
taodm 2007-05-30
  • 打赏
  • 举报
回复
看《STL源码剖析》,关于stl内存管理的章。原因里面都写着呢。
lightnut 2007-05-30
  • 打赏
  • 举报
回复
这个不是你的代码的问题.
试以下下面这个, 它会报告你的代码中的内存泄露(如果有, 在这个例子中
当然有.与你的结果比较下, 就知道你原来的内存泄露是MS的问题:)

#ifdef _DEBUG
#ifdef new
#undef new
#endif

#define _CRTDBG_MAP_ALLOC
#include <stdlib.h>
#include <crtdbg.h>

#include <xdebug>

#define new new(_NORMAL_BLOCK,__FILE__,__LINE__)
#endif

#include <vector>

using namespace std;


int main()
{

int iarr[]={3,2,5,6,33,4,1,9};

vector<int> arr(iarr, iarr+sizeof(iarr)/sizeof(*iarr));

int * myint = new int[10];

system("pause");

_CrtDumpMemoryLeaks();

return 0;

}
星羽 2007-05-30
  • 打赏
  • 举报
回复
你用什么编译器

coolnick 2007-05-30
  • 打赏
  • 举报
回复
mark,帮顶~~~
lin_style 2007-05-30
  • 打赏
  • 举报
回复
我希望是我的问题

15,440

社区成员

发帖
与我相关
我的任务
社区描述
C/C++ 非技术区
社区管理员
  • 非技术区社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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