文章目录
1 代码示例
#ifdef _DEBUG
#define DEBUG_CLIENTBLOCK new( _CLIENT_BLOCK, __FILE__, __LINE__)
#else
#define DEBUG_CLIENTBLOCK
#endif
#define _CRTDBG_MAP_ALLOC
#include <crtdbg.h>
#ifdef _DEBUG
#define new DEBUG_CLIENTBLOCK
#endif
//#include "vld.h" // visual leak detector 另一个内存泄漏检测工具
#include <iostream>
#include <queue>
#include <string>
using namespace std;
class Example
{
public:
Example();
Example(int newIndex);
virtual ~Example();
int m_Index;
};
Example::Example()
{
}
Example::Example(int newIndex)
{
m_Index = newIndex;
}
Example::~Example()
{
}
int main()
{
std::queue<Example*> MyTestQueue;
for (unsigned int i = 0; i < 10; ++i)
{
std::string tempStr = std::to_string(i);
Example* pExample = new Example(i);
MyTestQueue.push(pExample);
}
while (MyTestQueue.size() != 0)
{
Example* pExample = MyTestQueue.front();
MyTestQueue.pop();
delete pExample;
pExample = NULL;
}
_CrtDumpMemoryLeaks();
getchar();
return 0;
}
大家有兴趣可以访问我的个站:http://www.stubbornhuang.com