A client application running in a JVM needs enough memory to accommodate messages that flow in from the network as well as messages the client creates. If your client gets OutOfMemoryError errors, chances are that not enough memory was provided to handle the size or the number of messages being consumed or produced.
Your client might need more than the default JVM heap space. On most systems, the default is 64 MB but you will need to check the default values for your system.
Consider the following guidelines:
Evaluate the normal and peak system memory footprints when sizing heap space.
You can start by doubling the heap size using a command like the following:
java -Xmx128m MyClass
The best size for the heap space depends on both the operating system and the JDK release. Check the JDK documentation for restrictions.
The size of the VM’s memory allocation pool must be less than or equal to the amount of virtual memory that is available on the system.