• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!
  • Hello [name]! Thanks for joining the GMC. Before making any posts in the Tech Support forum, can we suggest you read the forum rules? These are simple guidelines that we ask you to follow so that you can get the best help possible for your issue.

Does destroying an instance also automatically destroys particle types created in it?

S

sekibanki

Guest
I think that may be causing some memory leaks in my game, but I'm not so sure.
 

FrostyCat

Redemption Seeker
GMS is NOT a garbage-collected environment in the general case. Only reals, strings and arrays are garbage-collected. Anything dynamically allocated resource referred to by an ID (e.g. particle systems, data structures, buffers, etc.) must be manually cleaned up.

With GMS 1.4, though you can use Destroy event for the cleanup, you should note that the clearing of non-persistent instances at the end of a room DOES NOT trigger it. To handle this, add this to the Room End event of any object implementing a Destroy event containing only cleanup code:
Code:
if (!persistent) {
  event_perform(ev_destroy, 0);
}
If you have code that should only trigger on an explicit destroy (e.g. a sound playing on death), you need a slightly different strategy. Leave the explicit-destroy code in Destroy, move the cleanup code to a User Event (my convention is 13), and use event_user() to call it on both Destroy and Room End. In Room End, you should also check the !persistent condition so that persistent instances don't clean up after themselves while they are still alive.

With GMS 2, there is a new dedicated Cleanup event that unconditionally runs whenever an instance goes out of existence by any reason.
 
S

sekibanki

Guest
Oh yes, I was suspecting that might be the case. Thanks.
With GMS 1.4, though you can use Destroy event for the cleanup, you should note that the clearing of non-persistent instances at the end of a room DOES NOT trigger it.
That I didn't know. In fact, that may also be a source of memory leak because I always assumed the Destroy event ran when a non-persistent object was killed by room change. Kinda counterintuitive I guess, but at least it was fixed later.
 
Top