• 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!

Legacy GM game_restart and objects question

A

ajax_sripts

Guest
When I use game_restart(), do objects execute "on destruction" event?
I have some objects that have ds_grid_create inside, game creates them in the beggining and they always active. To avoid memory leaks, will it be enough to destroy grids in "on destruction" event of those objects, or do I need to execute "ds_grid_destroy" in the script with "game_restart()"?
I'm using gm8.1.
 

Yal

šŸ§ *penguin noises*
GMC Elder
Game and room restarts doesn't destroy objects. But you can make that happen yourself by putting instance_destroy() in the Room End and Game End events.

(If you just wanna prevent memory leaks, there's no need to free up data structures on Game End - the OS will reclaim all your game's memory when it closes)
 
A

ajax_sripts

Guest
Put it in the Cleanup Event. That's guaranteed to run.
There is no celanup event in gm8.1

Game and room restarts doesn't destroy objects. But you can make that happen yourself by putting instance_destroy() in the Room End and Game End events.
So Game End event triggers on both game_end() and game_restart()?

(If you just wanna prevent memory leaks, there's no need to free up data structures on Game End - the OS will reclaim all your game's memory when it closes)
Do you mean, OS will reclaim memory when player exit the game? Because my game restarts a lot and there's definitely a leak.
 

TheouAegis

Member
Ending the game means the program closes. Restarting the game means the game is still running, GM just resets some things and executes the first routine of the program. A game restart is not a game end. That's what he's saying.

You can test yourself if Game End runs on game_restart(). Just put a show_message() call in it.

You need to destroy all data structures, particle emitters, generated objects/sprites/whatever. I can't remember if you need to free surfaces, but do it anyway. You can only count on GM to clear variables. Anything set using a function with _create* or _duplicate* in its name needs to be destroyed.
 
Top