Fixed a memory leak when a connection is closed the topics should also be removed if they are empty