How to close chats properly

Hey all,

I am new to Smack and I am developing a client. I love the Smack library it seems very intuitive and easy to use. I am currently working on a very light client just as a project. We are pretending this is running on a phone but it is actually written as normal Java app.

In my app I register a ChatManagerListener and listen for new chats. chatCreated() gets called successfully for a new message from a new chat. Since i know this is the first time the chat is created I also register a message listener to each new chat.

I have my own hashmap of <RosterEntry, Chat> and a method called closeChat(). When this method is invoked I am trying to clean up resources by removing the chat from the hashamp and unregistering all message listeners. However, I noticed that since a new chat has been created each time a new message is received from that user gets lost, meaning that chatCreated() does not get called. It seems as if the Chat object still remains on Smack library and it does not trigger chatCreated().

I hope I make sense. I just want an elegant way to close chats. Is there anything I am missing?

Thanks!