默认方法编译的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
这里就是内存泄露的信息!