Hi Angel,
I got memory leak. Cost me a few days to trace this.
Here is a part of code cause the problem:
for (int i = 0; i < 10000; i++) {
asIScriptContext *scriptContext = engine->CreateContext();
engine->ExecuteString("testMemory", "printStr();", &scriptContext);
scriptContext->Release();
}
if the context is NULL, there is memory leak. otherwise it keep leaking the memory.
wat's wrong here? and also, is there any compiling option for angelscript to detect the memory leak? do u use malloc, new in the angelscript? I saw you use #include <crtdbg.h> in the test future project. I believe angelscript support default memory leak detection.
Anyway, here is the full code just in case u need it:
asIScriptEngine *engine = asCreateScriptEngine(ANGELSCRIPT_VERSION);
engine->SetEngineProperty(asEP_ALLOW_UNSAFE_REFERENCES, 1);
//int result = engine->SetMessageCallback(asFUNCTION(MessageCallback), 0, asCALL_CDECL);
RegisterStdString(engine);
asERetCodes nRet = (asERetCodes) engine->RegisterGlobalFunction("void print(const string ∈)", asFUNCTIONPR(printString, (string&), void), asCALL_CDECL);
assert( nRet >= 0 );
asIScriptModule *module = engine->GetModule("testMemory", asGM_CREATE_IF_NOT_EXISTS);
char* code = "bool printStr()"
"{ "
"print('how are you'); "
"return true; "
"}";
nRet = (asERetCodes) module->AddScriptSection("section1", code, strlen(code));
nRet = (asERetCodes) module->Build();
for (int i = 0; i < 10000; i++) {
asIScriptContext *scriptContext = engine->CreateContext();
engine->ExecuteString("testMemory", "printStr();", &scriptContext);
scriptContext->Release();
}
engine->Release();
here is the print message:
void printString(string &str) {
printf("%s", str.c_str());
}
Cheers