Dinhero21 / game-engine

Fully Open Source Game and Game Engine
0 stars 0 forks source link

Weak Event Emitter #14

Open Dinhero21 opened 9 months ago

Dinhero21 commented 9 months ago

This probably shouldn't be an issue but I'm just creating this for means of documentation.

The way IO Events are handled (more specifically the Mouse Prioritization System) uses a wacky EventFrame system that requires you to call free() when you don't need the object anymore.

Of course, this is very error-prone as memory leaks can easily be created by simply forgetting to call free() which should be the garbage collector's job anyway!

So, the idea is to create an alternative to EventTargets / node:events that uses WeakMaps (or WeakRef Maps for iteratability) that wouldn't keep strong references that would make it automatically garbage-collectable.

(this might be best made into its own standalone package, weak-events anyon- oh wait that's already taken)