• Advertisement
Sign in to follow this  

Reference type memory leak?

This topic is 1121 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

So I have a reference type where i register the asBEHAVE_ADDREF and asBEHAVE_RELEASE behaviours, and I construct this reference type in C++. So in AngelScript I have a C++ method that returns this reference type, but if I never assign the returned value to anything the reference behaviours are never called so the object never gets deleted. Is there something I can do to detect this or have I done something wrong?

 

 

So basically this leaks memory:

sound.Play2D();

 

and this does not:

SoundInstance@ si = sound.Play2D();

Share this post


Link to post
Share on other sites
Advertisement

There should not be any memory leak in either case.

 

 

How have you registered Play2D()? And how is it implemented?

 

 

If you have registered it to return a handle, i.e. "SoundInstance @Play2D()" then the implementation should increment the ref count for the returned handle. AngelScript will then call Release() on it when it is no longer used (even if you don't explicitly assign it to any variable).

 

If you have registered it to return a reference, i.e. "SoundInstance &Play2D()" then the implementation must not increment the ref count for the returned reference, as AngelScript will not call Release() on it.

Share this post


Link to post
Share on other sites

Ah alright, I changed it to return a handle and I incremented the ref count, so now it works. Thank you.

Share this post


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

  • Advertisement