• Hey! Guest! The 40th (!!!) GMC Jam will take place between February 25th, 12:00 UTC to March 1st 12:00 UTC. Why not join in this very special anniversary jam! Click here to find out more!

SOLVED Recreating Data Structures and ds_exists

Jam373

Member
So I learnt the hard way that ds_exists has issues. I have a function that creates data structures, that I call several times in different contexts. Mosts of those contexts have the data structures destroyed as soon as the function is finished. One of them however "requires" (I could work around if necessary) the function to run several times before destroying the DSs. So I thought I'd change the function to only create the DSs if they don't already exist via ds_exists, but it turns out as I'm sure many of you are aware that if the variable storing the id has been previously used for the DS, even if destroyed, ds_exists will return true.

Anyway, long preamble, probably not needed but whatever. Instead I've opted for keeping my function as it was previously and just recreating the DSs everytime the function is called. Everything works as normal. However I have concerns that recreating DSs that already exist causes a memory leak. That the old DSs lose their "identifier" and are lost to the ether, being replaced by the new ones but still taking up memory. Am I correct? I know what to do to fix it if this is the case but I just want to know if that is or isn't happening.
 
Last edited:

Nidoking

Member
When you destroy a data structure, set the variable that formerly contained the handle to some other value, like noone. Now a ds_exists on that variable is guaranteed to fail.
 

Jam373

Member
When you destroy a data structure, set the variable that formerly contained the handle to some other value, like noone. Now a ds_exists on that variable is guaranteed to fail.
Thanks very useful knowledge! Really helpful.

However my question still stands, have I caused a memory leak?

edit: Nvm, google finally gave the answer, it does as I suspected cause a memory leak.
 
Top