You're mixing abstractions here. This cleanup should happen in main, where the listeners were registered.