妈了个逼, 这段简单的STL都内存泄露了?哪出有关问题了
妈了个逼, 这段简单的STL都内存泄露了?哪出问题了?
#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.
------解决方案--------------------
你用什么编译器
------解决方案--------------------
以前的某个帖子里讨论过类似的问题(当然,那个帖子里大部分人都没搞清为什么,但是他们都以为自己搞清了。。。)
#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才会析构,内存才会被释放!!
}
------解决方案--------------------
诶,不要转牛角尖哦。。_CrtDumpMemoryLeaks();表示的是当前的内存泄漏情况,在你调用这个函数的时候任何这个时刻没有被释放的内存,它都会当做内存泄漏。。
------解决方案--------------------
linux -> Valgrind
#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.
------解决方案--------------------
你用什么编译器
------解决方案--------------------
以前的某个帖子里讨论过类似的问题(当然,那个帖子里大部分人都没搞清为什么,但是他们都以为自己搞清了。。。)
#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才会析构,内存才会被释放!!
}
------解决方案--------------------
诶,不要转牛角尖哦。。_CrtDumpMemoryLeaks();表示的是当前的内存泄漏情况,在你调用这个函数的时候任何这个时刻没有被释放的内存,它都会当做内存泄漏。。
------解决方案--------------------
linux -> Valgrind