powered by Jive Software

Memory Leak in BookmarkManager

Hi,

we currently have huge troubles with Memory Leaks. While working on the cause, I’ve found that one cause is Smack’s BookmarkManager.

It keeps connections in it’s static HashMap and doesn’t use weak references (as other manager classes do).

Therefore connections are kept in memory after disconnecting/losing reference to them and everything else, what is attached to a connection, too (like other manager classes). See attached screenshot from VisualVM.

Reproducible with this code (tested with 3.3.1 and 3.4.1):

public class SmackTest {

public static void main(final String[] args) {

Executors.newFixedThreadPool(1, new ThreadFactory() {

@Override

public Thread newThread(Runnable r) {

return new Thread(r, “Main Application Thread”);

}

}).execute(new Runnable() {

@Override

public void run() {

System.out.println(SmackConfiguration.getVersion());

for (int i = 0; i < 10; i++) {

System.out.println(“Connecting…” + i);

Connection connection = new XMPPConnection(“server”);

try {

connection.connect();

connection.login(“admin”, “admin”);

BookmarkManager.getBookmarkManager(connection);

} catch (XMPPException e) {

e.printStackTrace();

} finally {

connection.disconnect();

}

}

}

});

}

}

Thanks for reporting, logged as SMACK-554