Adventure Game Studio

AGS Support => Advanced Technical Forum => Topic started by: Besh on Wed 03/05/2006 20:13:00

Title: Plugins: Deleting objects from managed object pool
Post by: Besh on Wed 03/05/2006 20:13:00
Which is the correct sequence for deleting an object from managed object pool at runtime (not when the game end)???
Title: Re: PROBLEM with managed object pool
Post by: Scorpiorus on Wed 03/05/2006 22:31:21
You mean from within a plugin?

You just need to implement the IAGSScriptManagedObject::Dispose() method of each managed class (ie. free memory there). AGS should then automatically invoke this method when an object is not needed anymore. You shouldn't delete them explicitly.
Title: Re: PROBLEM with managed object pool
Post by: Besh on Thu 04/05/2006 08:22:24
OK, but how can I force the engine to delete an object???
Title: Re: PROBLEM with managed object pool
Post by: Scorpiorus on Fri 05/05/2006 18:05:22
Well, the whole idea with an object being managed is that you are not supposed to manually destroy it, nor force the engine to do that. Instead, the engine will decide on when a managed object is not needed anymore and will try to discard it.

If you really need to delete it at some specific moment then just don't make it managed, and control its lifetime within a plugin code as you like. You should not however expose such object to the script then, since the engine would crash on accessing the non existent object from within a script (or you can expose it as a non-managed object but make sure you don't destroy it anywhere, unless on engine shutdown).
Title: Re: Plugins: Deleting objects from managed object pool
Post by: Pumaman on Mon 08/05/2006 20:28:25
Yes, you cannot delete a managed object explicitly.

The whole point of managed objects is that they are automatically destroyed when the last script reference to them is removed. If you were able to manually delete the object before that, it would crash the script interpreter.