Advertisement Jump to content
Sign in to follow this  
Jason Goepel

Memory Leak When Registering Implicit Reference Cast for Template

This topic is 1785 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I haven't had the time to generate a simplified example of this bug yet, but I figured I would report it while I work on one.


I found that under certain conditions a "asBEHAVE_IMPLICIT_REF_CAST" behavior will leak.  Here is what I know.


- There is no leak if I do not register any "asBEHAVE_IMPLICIT_REF_CAST" behavior.

- There is no leak if I do not register any template specializations.

- The leaked behavior is the one created during the registration of the template class, NOT the specialization.


It appears that registering the template specializations (or the asBEHAVE_IMPLICIT_REF_CAST behaviors in those specializations) is preventing the proper cleanup of the asBEHAVE_IMPLICIT_REF_CAST behaviors in the template class.


I will try to develop a simplified example, but there are a lot of elements involved.  Let me know if you are able to reproduce the leak so I don't have create the example.


If there is anything I can 


The leaked memory is allocated with the asNEW calls in asCScriptEngine::AddBehaviourFunction

int asCScriptEngine::AddBehaviourFunction(asCScriptFunction &func, asSSystemFunctionInterface &internal)
	asUINT n;

	int id = GetNextScriptFunctionId();

	asSSystemFunctionInterface *newInterface = asNEW(asSSystemFunctionInterface)(internal);
	if( newInterface == 0 )
		return asOUT_OF_MEMORY;

	asCScriptFunction *f = asNEW(asCScriptFunction)(this, 0, asFUNC_SYSTEM);
	if( f == 0 )
		asDELETE(newInterface, asSSystemFunctionInterface);
		return asOUT_OF_MEMORY;

	asASSERT( != "" && != "f");
	f->name           =;
	f->sysFuncIntf    = newInterface;
	f->returnType     = func.returnType;
	f->objectType     = func.objectType;
	f->id             = id;
	f->isReadOnly     = func.isReadOnly;
	f->accessMask     = defaultAccessMask;
	f->parameterTypes = func.parameterTypes;
	f->inOutFlags     = func.inOutFlags;
	for( n = 0; n < func.defaultArgs.GetLength(); n++ )
		if( func.defaultArgs[n] )


	// If parameter type from other groups are used, add references
	if( f->returnType.GetObjectType() )
		asCConfigGroup *group = FindConfigGroupForObjectType(f->returnType.GetObjectType());
	for( n = 0; n < f->parameterTypes.GetLength(); n++ )
		if( f->parameterTypes[n].GetObjectType() )
			asCConfigGroup *group = FindConfigGroupForObjectType(f->parameterTypes[n].GetObjectType());

	return id;

I have attached my engine configuration.  I have reduced it quite a bit, but it still shows the leak.  I am noticing that even though I registered a template specilization Array<int8> it doesn't show in the configuration file.  I hope this helps.

Share this post

Link to post
Share on other sites

Upon further investigation, the leak is not the worst of my problems.  The implicit reference cast isn't called when it should, even though it was registered.  Perhaps it got replaced somewhere in the registration process.

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using, you agree to our community Guidelines, Terms of Use, and Privacy Policy. is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!