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.