Plugins: Deleting objects from managed object pool

Started by Besh, Wed 03/05/2006 20:13:00

Previous topic - Next topic

Besh

Which is the correct sequence for deleting an object from managed object pool at runtime (not when the game end)???
"Spread our codes to the stars,
You can rescue us all"
- Muse

Scorpiorus

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.

Besh

OK, but how can I force the engine to delete an object???
"Spread our codes to the stars,
You can rescue us all"
- Muse

Scorpiorus

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).

Pumaman

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.

SMF spam blocked by CleanTalk