rspec/rules/S6112/description.adoc

11 lines
691 B
Plaintext
Raw Normal View History

2021-01-12 16:11:41 +00:00
Subscribing to events without unsubscribing later on can lead to memory leaks or even duplicate subscriptions, i.e. code which is executed multiple times by mistake.
2021-02-02 15:02:10 +01:00
2021-01-12 16:11:41 +00:00
Even if there is no problem right now, the code is more difficult to review and a simple refactoring can create a bug. For example the lifetime of the event publisher could change and prevent subscribers from being garbage collected.
2021-02-02 15:02:10 +01:00
2021-01-27 13:42:22 +01:00
There are patterns to automatically unsubscribe, but the simplest and most readable solution remains to unsubscribe from events explicitly using ``++-=++``.
2021-01-12 16:11:41 +00:00
2021-02-02 15:02:10 +01:00
2021-01-27 13:42:22 +01:00
This rule raises an issue when a class subscribes to an even using ``+++=++`` without explicitly unsubscribing with ``++-=++``.