ace 内存管理有意思的问题
#include "ace/os.h"
#include <memory>
class aaa
{
private:
char * m_data;
unsigned int m_size;
public:
aaa(unsigned int size)
{
m_data = new char;
m_size = size;
}
~aaa()
{
delete m_data;
}
int put()
{
return m_size;
}
};
int main (int argc, char *argv[])
{
for(int i = 0; i < 1000;i++)
{
std::auto_ptr<aaa> a(new aaa(i * 1024));
//aaa * a = new aaa(1024 * 1024);
//char * a = new char;
printf("%d",a->put()/1024);
ACE_OS::sleep(1);
}
ACE_OS::sleep(1000);
}
使用 windows 的任务管理器查看内存变化,
2772->398->8419->298.......
是 ace 接管有内存池,还是操作系统内存管理很有意思 这个是你释放失败导致~aaa()
{
delete[] m_data;
}
页:
[1]