Advertisement

Leak detection

Started by November 04, 2010 08:15 AM
3 comments, last by WitchLord 14 years ago
Is there a way to perform a leak detection test like the debug crt in VC?. For example, when I'm about to release the scripting engine, I *should* not have any references to objects, so it should be straightforward to ask the garbage collector or the scripting engine if it still holds references to objects, but how to do that?

Something like:

asIScriptEngine* engine = ...;

// run some scripts, and acquire object references


// Finish...

if (engine->GetTotalRefCount() > 0)
{
// Leaks!
}

engine->Release();

Thanks!

I don't think it'd be a straightforward as that. Modules can have global variables which can hold references so even if you're done with everything that doesn't mean that there won't be references live in the engine.
Advertisement
So, is there *any* way to check for leaks?
You can still use your CRT memory debug functions.
As AngelScript uses automatic memory management, there shouldn't be any leaks. If there are, then it would be a bug in the library that I need to fix, or the improper registration of application classes which needs to be fixed by the application developer.

In either case, it isn't something that could be detected by the library. It wouldn't be a leak if the library knew about it. ;)

You can get the number of objects known to the GC with a call to asIScriptEngine::GetGCStatistics. Only objects that have a chance of forming circular references will be known to the GC, so that it can detect and resolve these if necessary. Remember that the Garbage Collector is not automatically invoked (except when releasing the engine), so the application needs to do that (preferably incrementally to avoid potentially blocking the application for long periods).

AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

This topic is closed to new replies.

Advertisement