Hi there!!
I have a problem with a memory leak that I don't know if it is a problem on how I register a class or is it an AngelScript problem. It only happens when I have an object from a registered C++ class. In this example, I have a Sprite class registered.
Here is an example of the code I'm using:
interface Actor {
bool Initialize();
void Unload();
}
class Pepe : Actor {
Sprite spr;
bool Initialize() {
if (!spr.Load("data/graphics/uridium.spr"))
return false;
return true;
}
void Unload() {
spr.Unload();
}
}
Actor@[] pepe;
const int COUNT = 1000;
//==============================================
// Actualización
bool Update(float dt) {
if (KeyDown(KEY_1)) {
pepe.resize(COUNT);
for (int i=0; i < COUNT; i++) {
Pepe caca;
if (!caca.Initialize())
return false;
@pepe = @caca;
}
}
if (KeyDown(KEY_2)) {
for (int i=0; i < COUNT; i++) {
pepe.Unload();
@pepe = null;
}
while (GC(true) != 0);
pepe.resize(0);
}
return true;
}
//==============================================
So, when I press "1", the application memory usage increases by 3 mb but when I press "2" it doesn't decrease. Here's how I register the Sprite class:
if (ScriptMgr::RegisterObjectType(_className, sizeof(Sprite), asOBJ_CLASS_CD) < 0)
return false;
if (ScriptMgr::RegisterObjectBehaviour(_className, asBEHAVE_CONSTRUCT,"void f()", asFUNCTION(Constructor), asCALL_CDECL_OBJLAST) < 0)
return false;
if (ScriptMgr::RegisterObjectBehaviour(_className, asBEHAVE_DESTRUCT,"void f()", asFUNCTION(Destructor), asCALL_CDECL_OBJLAST) < 0)
return false;
if (ScriptMgr::RegisterObjectBehaviour(_className, asBEHAVE_ADDREF,"void f()", asMETHOD(Sprite, AddRef), asCALL_THISCALL) < 0)
return false;
if (ScriptMgr::RegisterObjectBehaviour(_className, asBEHAVE_RELEASE,"void f()", asMETHOD(Sprite, Release), asCALL_THISCALL) < 0)
return false;
I don't know what's going on here.
See you soon!
=====================================Regards,Juan Pablo (McKrackeN) Bettini Psychoban Official Site:http://www.psychoban.comPsychoban on iTunes App Store:http://itunes.apple.com/us/app/psychoban/id378692853?mt=8