it seems to me that a MultiUserChat which is no longer in use cannot be garbage collected under some circumstances.
If I add a listener to a MultiUserChat object (addMessageListener) other listeners will be added to the XMPPConnection (connection.addPacketListener).
These listeners wont be removed if I call .leave() or the like.
Thus, the XMPPConnection keeps references to listeners which in turn probably reference the MultiUserChat object. I think if you have a long running XMPPConnection no MultiUserChat objects can be garbage collected.
Maybe I am mistaken, some feedback would be great.
There are definitely some bugs with how MultiUserChat handles listeners. I ran into them myself when I was trying to allow users to join a room, leave it, and then later join again. When the room was re-created the listeners were not established correctly and so the ParticipantStatusListener didn’t work. I think the bugs I ran into were due to how MultiUserChat uses RoomListenerMultiplexor, but it’s been awhile and I can’t remember for sure.
After being stuck on the problem for a while, I finally decided to check the Spark source code to see how they made it work. I discovered that they do not even use the MUC-specific listeners, but instead just setup a generic PacketListener and process the raw packets instead. So I did the same thing in my application and it seems to work reliably that way.