2013-04-11

Issue with my event solution...

This will be a short update mostly as a note to self on why it is bad to use events or something with a strong connection between classes in a solution with garbage collections.

Basically, I have some home brewn event system based around

  • Singleton Controller
  • Event/Command with id[string]
  • Registering interest on controller with ( id[string], cb[Function/Delegate])
And then I would add connection between classes similar to this:
            Controller.instance.registerInterest("id_1", onSpawnParticles);
            Controller.instance.registerInterest("id_2", onReloadDatabase);

Now, due to the issue of the callback being a function, whenever I want to delete something that registered their interest at Controller I would have to manually remove all connections or else GC will always find connections to that class...

I probably should have done this solution with the help of Observer-pattern so I only get one callback and thus only have to do one "unregister" call for each class that falls out of scope... Much easier :o)

Ah well, good thing to learn the hard way :)

Inga kommentarer:

Skicka en kommentar