🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

Reference type memory leak?

Started by
1 comment, last by Myran 9 years, 5 months ago

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();

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.

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

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

This topic is closed to new replies.

Advertisement