Author Topic: No "Delete" on Dictionaries?  (Read 118 times)

Monsieur OUXX

  • Mittens Vassal
  • Cavefish
  • Mittens Half Initiate
    • I can help with proof reading
    • I can help with translating
    • I can help with voice acting
    • Monsieur OUXX worked on one or more games that won an AGS Award!
    •  
    • Monsieur OUXX worked on one or more games that was nominated for an AGS Award!
No "Delete" on Dictionaries?
« on: 16 Sep 2020, 18:55 »
Just to be 100% sure, I'd rather ask.

the lifecycle of a dynamic sprite is :
Code: Adventure Game Studio
  1. DynamicSprite* spr = DynamicSprite.Create(...);
  2. ...
  3. spr.Delete();
  4.  


But what about dictionaries?
Code: Adventure Game Studio
  1. Dictionary* d= Dictionary.Create(...);
  2. ...
  3. d.Delete(); // <-- this function does not exist
  4.  
 

Re: No "Delete" on Dictionaries?
« Reply #1 on: 16 Sep 2020, 19:11 »
It gets deleted as soon as there's no reference to object left, and DynamicSprite too.

Monsieur OUXX

  • Mittens Vassal
  • Cavefish
  • Mittens Half Initiate
    • I can help with proof reading
    • I can help with translating
    • I can help with voice acting
    • Monsieur OUXX worked on one or more games that won an AGS Award!
    •  
    • Monsieur OUXX worked on one or more games that was nominated for an AGS Award!
Re: No "Delete" on Dictionaries?
« Reply #2 on: 17 Sep 2020, 08:16 »
It gets deleted as soon as there's no reference to object left

Perfect.

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

  • Local Moderator
  • * KILL* * KILL * * KILL *
    • Lifetime Achievement Award Winner
Re: No "Delete" on Dictionaries?
« Reply #3 on: 17 Sep 2020, 09:43 »
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).