Regarding CloneObject() inner workings

What happens to an object after it was created by CloneObject() and subsequently not used anywhere? I mean - since it is C# object under-the-hood, does it get GC'ed, or does it hold some references somewhere?

Concrete example:
Lets imagine I want to have an object called "SceneManager" that will hold the state of some scene, and I want to allow several scenes happening at once.
If I were to create a "prototype" of SceneManager, clone it each time I want to start a scene and then discard it, would those discarded objects linger on indefinitely until Quest player is closed?


How are you discarding them? If you are destroying them, they may well get garbage collected. Otherwise they will linger indefinitely, and if the player saves the game, they will also be saved, and will get loaded with everything else.

This is not specific to clones. Clones work the same as everything else once created.


By "discarding" I mean what I would like to do, until you mentioned "destroying" haven't seen explicit way to destroy them.
Do you mean that the destroy() function that I see at :http://docs.textadventures.co.uk/quest/scripts/destroy.html will cause the object to be eventually GCed?


All objects are stored in a global dictionary whose key is the object name. So there is always at least one reference to every object.
The only way to remove an object from this dictionary is to call destroy(), which explicitly destroys the object.


The function that The Pixie uses is. RemoveObject (this)

Edit:
Sorry. I wrote the wrong code...


All objects are stored in a global dictionary whose key is the object name. So there is always at least one reference to every object.
The only way to remove an object from this dictionary is to call destroy(), which explicitly destroys the object.

Good to know that, thanks! Maybe its a habit that is not applicable at Quest scopes, but I do worry about memory usage :)


This topic is now closed. Topics are closed after 60 days of inactivity.

Support

Forums