Fixed a memory leak when a connection is closed the topics should also b...

...e removed if they are empty