title: Activemq went out of memory when sending large files over queue
body: <p>When sending 100MB size messages using queue, ActiveMQ runs into out of memory error, we are using file cursor for the queue -</p>
  
  <p>Queue Detail - Our producer are sending NON-Persistent messages at the size of 100MB per messages and the producer will just keep producing through a while loop of the same 100MB messages.</p>
  
  <p>We use the default heap size that came with activeMQ which is 1GB max.</p>
  
  <p>We have the ActiveMQ config setting as follows:</p>
  
  <pre><code>&lt;policyEntry queue="&gt;" producerFlowControl="false" memoryLimit="512mb" maxPageSize="1000000"&gt;               
  &lt;pendingQueuePolicy&gt;                            
  &lt;fileQueueCursor /&gt; 
  &lt;/pendingQueuePolicy&gt;
  &lt;/policyEntry&gt;  
  </code></pre>
  
  <p>On the consume side we have a Async consumer which will keep listening on messages coming in and send auto-ack.</p>
  
  <p>After this program runs for a while activeMQ throws the following error:</p>
  
  <pre><code>    2016-04-21 14:52:18,961 | ERROR | Error in thread 'ActiveMQ BrokerService.worker.1' | org.apache.activemq.broker.BrokerService | ActiveMQ BrokerService.worker.1
  java.lang.OutOfMemoryError: Java heap space
      at org.apache.activemq.util.DataByteArrayOutputStream.ensureEnoughBuffer(DataByteArrayOutputStream.java:249)[activemq-client-5.13.1.jar:5.13.1]
      at org.apache.activemq.util.DataByteArrayOutputStream.writeBoolean(DataByteArrayOutputStream.java:140)[activemq-client-5.13.1.jar:5.13.1]
      at org.apache.activemq.openwire.v11.BaseDataStreamMarshaller.looseMarshalByteSequence(BaseDataStreamMarshaller.java:627)[activemq-client-5.13.1.jar:5.13.1]
      at org.apache.activemq.openwire.v11.MessageMarshaller.looseMarshal(MessageMarshaller.java:300)[activemq-client-5.13.1.jar:5.13.1]
      at org.apache.activemq.openwire.v11.ActiveMQMessageMarshaller.looseMarshal(ActiveMQMessageMarshaller.java:111)[activemq-client-5.13.1.jar:5.13.1]
      at org.apache.activemq.openwire.v11.ActiveMQTextMessageMarshaller.looseMarshal(ActiveMQTextMessageMarshaller.java:111)[activemq-client-5.13.1.jar:5.13.1]
      at org.apache.activemq.openwire.OpenWireFormat.marshal(OpenWireFormat.java:161)[activemq-client-5.13.1.jar:5.13.1]
      at org.apache.activemq.broker.region.cursors.FilePendingMessageCursor.getByteSequence(FilePendingMessageCursor.java:480)[activemq-broker-5.13.1.jar:5.13.1]
      at org.apache.activemq.broker.region.cursors.FilePendingMessageCursor.flushToDisk(FilePendingMessageCursor.java:440)[activemq-broker-5.13.1.jar:5.13.1]
      at org.apache.activemq.broker.region.cursors.FilePendingMessageCursor.onUsageChanged(FilePendingMessageCursor.java:401)[activemq-broker-5.13.1.jar:5.13.1]
      at org.apache.activemq.usage.Usage$1.run(Usage.java:308)[activemq-client-5.13.1.jar:5.13.1]
      at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)[:1.8.0_74]
      at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)[:1.8.0_74]
      at java.lang.Thread.run(Thread.java:745)[:1.8.0_74]
  </code></pre>
  
  <p>Does anyone knows how to resolve this? This doesn't seems to be happening when I keep sending smaller size messages, For example, messages that are less than 10MB.</p>