Jump to content

  • Log In with Google      Sign In   
  • Create Account

Interested in a FREE copy of HTML5 game maker Construct 2?

We'll be giving away three Personal Edition licences in next Tuesday's GDNet Direct email newsletter!

Sign up from the right-hand sidebar on our homepage and read Tuesday's newsletter for details!


We're also offering banner ads on our site from just $5! 1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


- - - - -

memory leak detected


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
2 replies to this topic

#1 abrken   Members   -  Reputation: 130

Like
0Likes
Like

Posted 15 October 2004 - 03:29 AM

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.

Sponsor:

#2 Andreas Jonsson   Moderators   -  Reputation: 3415

Like
0Likes
Like

Posted 15 October 2004 - 08:06 AM

Thanks for letting me know.

I've found and fixed the problem.

The change needed is the addition of the following statements in asCModule::~asCModule() right after Reset();


if( builder )
{
delete builder;
builder = 0;
}



Regards,
Andreas

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

#3 abrken   Members   -  Reputation: 130

Like
0Likes
Like

Posted 15 October 2004 - 08:41 AM

Thank's for the speedy fix !

AbrKen.




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS