[rabbitmq-discuss] Problem with RabbitMQ Java Client (Memory leak)

Yogesh Ketkar yogimogi at gmail.com
Tue Jan 31 17:49:11 GMT 2012

I am using rabbitmq-java-client-bin-2.7.1/rabbitmq-client.jar with
RabbitMQ 2.7.1 Server.

Just run this code

public static void main(String[] argv) throws IOException {
    ConnectionFactory f = new ConnectionFactory();
    Connection c = f.newConnection();
    for(int i = 0; i < 20000; ++i) {
        Channel ch = c.createChannel();
    while(true) {}

While program is running, observe the memory usage, it keeps on
Get process id and do following
jmap -dump:format=b,file=yo.bin  <pid>
jhat jhat -J-mx768m -stack false yo.bin
Once jhat brings up http server, go here

20001 instances of class com.rabbitmq.client.impl.AMQCommand
20001 instances of class com.rabbitmq.client.impl.CommandAssembler
20000 instances of class com.rabbitmq.client.ShutdownSignalException
20000 instances of class com.rabbitmq.client.impl.AMQImpl$Channel
20000 instances of class com.rabbitmq.client.impl.ChannelN
20000 instances of class com.rabbitmq.client.impl.ConsumerDispatcher

In-spite of closing all the channels, not only channels but associated
objects (ShutdownSignalException, ChannelClose) continue to consume
For sure, knowing this now, I will use channelCreate call sparingly.

Is there a way to remedy this situation?
What is also worrying is instances of AMQCommand, so would this be the
case for each and every call of client library?

regards, Yogesh

More information about the rabbitmq-discuss mailing list