Showing posts with label memory leak. Show all posts
Showing posts with label memory leak. Show all posts

Saturday, June 20, 2009

ServiceMix MessageExchange memory leak


Are you observing memory leak in JBI components deployed in ServiceMix? First place to check will be whether the message exchanges are closed properly.

In the InOut message exchanges, after receiving message from provider , consumer should set the status as DONE in the exchange and again send it to provider.

Note - just setting the status to DONE is not enough , it must be send back to provider, otherwise the message exchanges will not be properly closed and will result in a memory leak.

E.g.-
inOutexchange.setStatus(ExchangeStatus.DONE); context.getDeliveryChannel().send(inOutexchange);

Memory leak in Java application


What are the first steps to do when notice that the newly developed Java application is not running continuously? Most of the time it may be due to memory leak.

First thing to do is study the memory usage/ thread creation patterns of the application. Different profiler tools are available in market for this.

Two tools I commonly use are
1. JProfiler
2. YourKit

In JProfiler - if there are memory leaks , total memory of the objects (which are leaking) will be shown against the class which created the memory.
Sometimes this may be misleading as the object references may be held by someone else , and that class is the real reason for the leak.

In my experience , identifying those classes were bit easier in YourKit.