title: RabbitMQ QueueingConsumer possible memory leak
body: <p>I have the following code to declare a queue:</p>
  
  <pre><code>Connection connection = RabbitConnection.getConnection();
  Channel channel = connection.createChannel();
  channel.queueDeclare(getQueueName(), false, false, false, null);
  consumer = new QueueingConsumer(channel);
  channel.basicConsume(getQueueName(), true,consumer);
  </code></pre>
  
  <p>and the following to get the next Delivery object and process it:</p>
  
  <pre><code>    Delivery delivery = null;
      T queue = null;
  
      //loop over, continuously retrieving messages
      while(true) {
  
          try {
              delivery = consumer.nextDelivery();
              queue = deserialise(delivery.getBody());
  
              process(queue);
  
          } catch (ShutdownSignalException e) {
              logger.warn("Shutodwon signal received.");
              break;
          } catch (ConsumerCancelledException e) {
              logger.warn("Consumer cancelled exception: {}",e.getMessage());
              break;
          } catch (InterruptedException e) {
              logger.warn("Interuption exception: {}", e);
              break;
          }
      }
  </code></pre>
  
  <p>The deserialise code.  As you can see I'm using Kryo:</p>
  
  <pre><code>public T deserialise(byte[] body) {
      Kryo kryo= new Kryo();
      Input input = new Input(body);
      T deserialised = kryo.readObject(input, getQueueClass());
      input.close();
  
      return deserialised;
  }
  </code></pre>
  
  <p>If I run this with a queue containing a large number of objects, after approximatelly 2.7 million objects I get an out of memory exception.  I found this originally by running it over night with data going in from JMeter at a rate ~90/s which at first it is consuming without any trouble, but in the morning I noticed a large number in RabbitMQ and an out of memory exception on the consumer.  I ran it up again and used the Eclipse Memory Analyzer to determine where this memory was being used.  From this I can see that the java.util.concurrent.LinkedBlockingQueue that is referenced by com.rabbitmq.client.QueueingConsumer is growing and growing until it runs out of memory.</p>
  
  <p>Do I need to do anything to tell Rabbit to release resources?</p>
  
  <p>I could increase the heap size but I'm concerned that this is just a short term fix and there might be something in my code that could bite me with a memory leak a few months into production deployment.</p>