Hello,
For many time now, I was getting memory leaks. I was knowing that those memory leaks came from AS but never figured out how this happens.
Finally, I have found where the memory leak take place, and how to reproduce it.
This is the code (from test_constructor.cpp) :
bool TestConstructor()
{
bool fail = false;
asIScriptEngine *engine = asCreateScriptEngine(ANGELSCRIPT_VERSION);
RegisterStdString(engine);
int r;
r = engine->RegisterObjectType("obj", sizeof(CTestConstructor), asOBJ_CLASS_C); assert( r >= 0 );
r = engine->RegisterObjectBehaviour("obj", asBEHAVE_CONSTRUCT, "void f()", asFUNCTIONP(ConstrObj, (CTestConstructor *)), asCALL_CDECL_OBJLAST); assert( r >= 0 );
r = engine->RegisterObjectBehaviour("obj", asBEHAVE_CONSTRUCT, "void f(int,int)", asFUNCTIONP(ConstrObj, (int, int, CTestConstructor *)), asCALL_CDECL_OBJLAST); assert( r >= 0 );
r = engine->RegisterObjectProperty("obj", "int a", offsetof(CTestConstructor, a)); assert( r >= 0 );
r = engine->RegisterObjectProperty("obj", "int b", offsetof(CTestConstructor, b)); assert( r >= 0 );
int a, b;
r = engine->RegisterGlobalProperty("int a", &a); assert( r >= 0 );
r = engine->RegisterGlobalProperty("int b", &b); assert( r >= 0 );
CBufferedOutStream out;
engine->AddScriptSection(0, TESTNAME, script1, strlen(script1), 0);
engine->Release();
// Success
return fail;
}
The memory leak come from the fact that a Script Section is added and nothing else (no Build, nor Execute) is made with the engine.
It seems that the
new asCScriptCode
that appear in as_builder::AddCode is never deleted.
Regards,
AbrKen.