4ian / GDevelop

🎮 Open-source, cross-platform 2D/3D/multiplayer game engine designed for everyone.
https://gdevelop.io
Other
11.56k stars 881 forks source link

Add dispose method to Runtimegame #7118

Closed danvervlad closed 2 weeks ago

danvervlad commented 3 weeks ago

Summary

This PR adds a new dispose functionality to the RuntimeGame class, which serves as an entry point for memory cleanup. The RuntimeGame.dispose method calls dispose on all relevant managers and resources, enabling the complete unloading of the game from memory when needed.

Changes

Impact

Though unused at present, this new dispose functionality in RuntimeGame allows for efficient memory cleanup when the game is no longer needed

4ian commented 2 weeks ago

Many thanks for this, we'll take a look as soon as possible.

I have a fairly high level question: what made you chose the word "dispose"? It's an open question :) I think it's a good choice. It could have been:

I like dispose.. I wonder if destroy could have worked, at the risk of confusing it with PixiJS/existing destroy in the runtime (but which is akin to what you implemented). Let me know your toughts and we'll review this in any case.

danvervlad commented 2 weeks ago

Many thanks for this, we'll take a look as soon as possible.

I have a fairly high level question: what made you chose the word "dispose"? It's an open question :) I think it's a good choice. It could have been:

  • delete => too generic and low levels (we only use this for .delete() objects allocated in the editor with webassembly/emscripten with new gd.Xxx). It's also usually attached to "new" (new/delete in C++). Probably not a good candidate.
  • destroy => that's what PixiJS uses internally and that's what we used for RuntimeObject renderers. It's interesting because it's still a "strong word".
  • dispose => that's what Three.js uses internally. It's a bit less "strong" than destroy. We don't use it yet but it has the advantage of having a slightly different meaning.
  • release => usually I see this related to low level memory allocation (reference counting). Probably not a good candidate.
  • unallocate/deallocate => too low level, like release

I like dispose.. I wonder if destroy could have worked, at the risk of confusing it with PixiJS/existing destroy in the runtime (but which is akin to what you implemented). Let me know your toughts and we'll review this in any case.

Thank you for the feedback! I chose dispose() based on previous experience. The term “destroy” is typically used for removing specific scene objects, whereas here, we’re working with resource managers and the entire game. For example, in Unity, destroy is specifically called with an object parameter, but in our case, it should be applied to managers and the game itself. Also, the “disposable” pattern is widely used in languages like TypeScript and C#, making it familiar and intuitive for developers.

Of cource destroy could work if you prefer it more.

4ian commented 2 weeks ago

Thank you, dispose sounds good and will help separate these actions from the "destroy" (to oppose to "create" actions) which are used in game (while "dispose" is related to the whole 'game engine' itself) 👍

I'm thinking if we could add an automated test for this. I'm tagging @D8H so we remember to talk about this.