No "Delete" on Dictionaries?

Started by Monsieur OUXX, Wed 16/09/2020 18:55:31

Previous topic - Next topic

Monsieur OUXX

Just to be 100% sure, I'd rather ask.

the lifecycle of a dynamic sprite is :
Code: ags

DynamicSprite* spr = DynamicSprite.Create(...);
...
spr.Delete();



But what about dictionaries?
Code: ags

Dictionary* d= Dictionary.Create(...);
...
d.Delete(); // <-- this function does not exist
 

Crimson Wizard

It gets deleted as soon as there's no reference to object left, and DynamicSprite too.

Monsieur OUXX

Quote from: Crimson Wizard on Wed 16/09/2020 19:11:29
It gets deleted as soon as there's no reference to object left

Perfect.

Quote from: Crimson Wizard on Wed 16/09/2020 19:11:29
and DynamicSprite too.
Are you saying that DynamicSprite.Delete is more of a relic from the past? It gets called automatically by the garbage collector?
 

Gilbert

Not completely. .Delete() can still be useful in case for dynamic sprites as they usually occupy a certain amount of memory and you may want to remove them manually sometimes.

For a dynamic sprite to have no reference to it, either a pointer to it is destroyed for being out of scoop or you repurpose it to point to something else, or you assign Null to this pointer (or other scenario, such as the sprite is no longer being referenced by an overlay, etc.).

Sometimes it is not that simple, say, when there are multiple references to a single dynamic sprite. If you don't use the .Delete() function, you have to make sure you trash all these references in order to destroy it, which may be a bit messy sometimes. By using .Delete() you can be sure that the sprite is destroyed immediately and the memory is released, without locating each and every reference (though there is still a danger that you destroy a sprite that is still used somewhere in the game).

SMF spam blocked by CleanTalk