04.11.2008

Smack Library Bug

posted by Karsten

For the better part of 1.5 days I’ve been bug hunting a problem in the MeAggregator code base. The problem arised when accessing a Smack library bespoke client using the Ruby xmpp4r library utilising the the Smack ChatManager (via threadid feature of Xmpp). Every so often the Smack client would seem forgetfull and forget about the thread and create a new one, even though the thread clearly was in use.

I tried everything debugging-wise, believe me, and was starting to give up. But I can now, gladly, declare that I found the bug. 8)

The Smack library store all the treads in a ReferenceMap using new ReferenceMap<String, Chat>(ReferenceMap.HARD, ReferenceMap.WEAK);

Unfortunately this allows the garbage collector of Java to remove the thread if it can’t find any references to the thread string in the memory. Obviously as all other references to the string isin Ruby these will be thrown out.

I’ve now added a simple hashmap to the code which stores the string / chat combination on the java side, and it works!!

I can see why Smack would like to free the memory, but I really believe this behaviour ought to be documented in the javadocs of Smack, so that the code can make provisions for it.

I probably should let them know…

Share
Tags: , ,

Place your comment

Please fill your data and comment below.
Name
Email
Website
Your comment