Followers 0

GC cannot free an object of type 'array', it is kept alive by the application

3 posts in this topic

I am creating a CScriptArray instance and returning it to the script as shown at the bottom of this page: http://www.angelcode.com/angelscript/sdk/docs/manual/doc_addon_array.html

The script function that receives this is registered like:

scriptEngine->RegisterGlobalFunction("body[]& duplicate(const body[] &in)", asFUNCTION(duplicate_bodies), asCALL_CDECL);


On MacOS, after using this function and then exiting the program I see the "GC cannot free an object of type 'array'" message. Just wondering if I'm doing something wrong, and if I can avoid this somehow.

0

Share on other sites

This message usually means that somewhere in the code the application is not properly releasing the references.

Does this problem only happen on MacOS?

Can you run the app with valgrind? It should be able to identify where this array is allocated from. With the call stack that valgrind shows I may be able to see if it is a problem in AngelScript or not.

You are using the latest release of AngelScript, right?

0

Share on other sites

At a second glance I think I spotted the problem.

If this isn't exclusive to MacOS, I believe the problem is that you registered the function as if returning a reference to the new array, but it should be a handle.

scriptEngine->RegisterGlobalFunction("body[]@ duplicate(const body[] &in)", asFUNCTION(duplicate_bodies), asCALL_CDECL);


When registered as a reference AngelScript won't decrease the ref count after it is done with it. This is correct if the function never incremented the ref count in the first place, but as you created a new array and didn't store it somewhere in the application it must be decremented.

0

Share on other sites

You are quite correct. I had these incorrect registrations littered all throughout my app :) Perhaps the page I mentioned above could show the corresponding example registration to use, might avoid this problem. I seem to remember at the time I first started instantiating and returning arrays to the script, that I was puzzled for a while about what to do when body[] did not work, and then very pleased with myself when I discovered that body[]& worked. It seems like no harm is done either way though. The only reason I come across this now is because I'm making a command-line mode for my app, so I see these messages showing up on stderr whereas when running in GUI mode they are easier to miss. I have not checked Windows yet, but interestingly these messages were not showing on Linux. Anyhow, it feels good to fix these little niggling things, thanks Andreas!

0

Create an account

Register a new account