Jump to content

  • Log In with Google      Sign In   
  • Create Account

FREE SOFTWARE GIVEAWAY

We have 4 x Pro Licences (valued at $59 each) for 2d modular animation software Spriter to give away in this Thursday's GDNet Direct email newsletter.


Read more in this forum topic or make sure you're signed up (from the right-hand sidebar on the homepage) and read Thursday's newsletter to get in the running!


- - - - -

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


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
3 replies to this topic

#1 iforce2d   Members   -  Reputation: 222

Like
0Likes
Like

Posted 25 May 2013 - 12:39 AM

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.



Sponsor:

#2 Andreas Jonsson   Moderators   -  Reputation: 3453

Like
0Likes
Like

Posted 25 May 2013 - 08:41 AM

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?


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 Andreas Jonsson   Moderators   -  Reputation: 3453

Like
0Likes
Like

Posted 25 May 2013 - 08:50 AM

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.


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

#4 iforce2d   Members   -  Reputation: 222

Like
0Likes
Like

Posted 25 May 2013 - 03:53 PM

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!






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