mlabs-haskell / godot-cardano

Integrated light wallet and off-chain SDK for the Godot engine and Cardano blockchain
https://mlabs-haskell.github.io/godot-cardano/
MIT License
3 stars 0 forks source link

Make sure that all exposed classes from our API are *not* Nodes if unnecessary #51

Closed rmgaray closed 4 months ago

rmgaray commented 5 months ago

Using too many Nodes is bad: it leads to memory leaks (especially if one uses remove_child instead of queue_free: generally one should always prefer the ~former~ latter).

However, Nodes are sometimes necessary. The HTTPRequest class is a Node, so any class that contains a HTTPRequest needs to be a Node.

When deciding a base class to extend, this should be the priority order:

  1. RefCounted (or Resource if persistence is required): automatic memory management, no need to worry about leaks [^1].
  2. Node: memory is somewhat managed automatically (a Node is deallocated whenever its parent is). But they can still be retained too much, for example if one removes a node from the scene tree but does not delete the node itself (as when using remove_child).
  3. Object: manual management.

Tasks:

[^1]: There can still be long-lived references or cyclic references, but this is still the best option I think.