Ogre中生成内存泄露信息(OgreLeaks.log)的方法

       默认方法编译的Ogre库,在使用时是不生成内存泄露信息的。要想生成内存泄露信息需要在OgreBuildSettings.h文件中将以下的宏定义设置成1,分别对应着Debug版和Release版:

#define OGRE_MEMORY_TRACKER_DEBUG_MODE 1

#define OGRE_MEMORY_TRACKER_RELEASE_MODE 1

      然后重新编译Ogre库。

         如果我们写的一个类也要判断一下是否有内存泄露,需要继承

         typedef AllocatedObject<GeneralAllocPolicy> GeneralAllocatedObject;

         typedef AllocatedObject<GeometryAllocPolicy> GeometryAllocatedObject;

         typedef AllocatedObject<AnimationAllocPolicy> AnimationAllocatedObject;

         typedef AllocatedObject<SceneCtlAllocPolicy> SceneCtlAllocatedObject;

         typedef AllocatedObject<SceneObjAllocPolicy> SceneObjAllocatedObject;

         typedef AllocatedObject<ResourceAllocPolicy> ResourceAllocatedObject;

         typedef AllocatedObject<ScriptingAllocPolicy> ScriptingAllocatedObject;

         typedef AllocatedObject<RenderSysAllocPolicy> RenderSysAllocatedObject;

其中的任意一个,比如

class testMemory: public Ogre::GeneralAllocatedObject
{
public:
	testMemory()
	{
	}
protected:
private:
};

int main()
{
	testMemory *tst = OGRE_NEW testMemory;
	Ogre::ManualObject* pobj = OGRE_NEW Ogre::ManualObject("obj");
	return 0;

}


 

编译运行之后就会看到在目标文件夹中生成OgreLeaks.log文件,或者在编译器的输出窗口就会看到

 

Ogre Memory: Detected memory leaks !!!

Ogre Memory: (2) Allocation(s) with total 553 bytes.

Ogre Memory: Dumping allocations ->

d:\example\tryogre\tryogre\trymemory.cpp(22) : {552 bytes} function: main

d:\example\tryogre\tryogre\trymemory.cpp(20) : {1 bytes} function: main

这里就是内存泄露的信息!

 

 

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值