Modules are now instanciated as shared pointers and so have to be stored somewhere in order to keep the module active. This explicity requires the user to keep track of the module (ie. save it locally) otherwise it will be deleted preventing the module to be shown.
I've also implemented a responsibility delegation pattern from MessageBroker
to the subscriber.
What I mean with this is that the subscriber will be responsible by maintaining active the subscription by preventing the deletition of the object returned when subscribing.
This object, that is a unique_ptr<Subscription>
, will unsubscribe automatically from the message broker preventing the program to crash when a module is deleted, since the subscription will also be invalidated (this is achieved by calling MessageBroker::unsubscribe
when the subscription is deleted, that is when the unique_ptr
will fall out of scope).
In past implementation it was common to forget to unsubscribe from the broker when the module was deleted. This would lead to memory leakage since a pointer to the deleted module would remain in the MessageBroker
and when a filter matched the subscription it would try to call a method on the deleted object, causing a sigfault.
Solves Refactoring MessageBroker
Solves Using Smart Pointers
It doesn't break Crash when deleting tab