I'm writing a small text-editor like utility for our in-house staff to use to modify a bunch of company specific files. I want design this in such a way we minimize leaky handlers and would like to ask for opinions.
There are different actions done based on the type of file loaded. I have each in a separate class, I instantiate and pass through the active tab's instance of the richtextbox. The implementation then subscribes to the following:
SelectionChanged TextChanged
Then depending on the type of file, they'll deal with their specific things. I've noticed that some of our internal devs don't unsubscribe from events and things leak. The control hangs around (It's not a MDI app, a panel + tab control + many richtextboxes).
What's a good way of delegating the resposibility of susbcribing to events to these implementations?
Should I write a proxy (which they all subscribe to) and my Richtextbox basically gets that proxy to call it for me when something happens - and I subscribe/unsubscribe as necessary when the tab changes? Are there any established patterns - maybe a Gang of Four? that may be what I should use?