You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@directory.apache.org by Donovan Du Plessis <do...@prism.co.za> on 2005/07/13 18:08:14 UTC

[mina] ByteBuffer allocation memory leak

Environment:
Processing multiple xml message requests on multiple socket connections.
Currently we are sending +/- 3000 xml requests per second to your MINA
implementation (IoHandlerAdapter).

Design:
When data is read on the socket connection, it is passed to an object
which breaks the data buffer down into individual packets.  These
'packets' are then encoded and written back to the session.

Symptoms:
Memory leaking is occurring when a new ByteBuffer is allocated to store
the 'packet'.

e.g. ByteBuffer buffer_ = ByteBuffer.allocate(lengthOfPacket);

We have used a java profiler to monitor the running application, and
found a memory leak is occurring at the allocation point.

Please could you advise us on how to overcome this problem, as the
documentation states that the allocated buffer needs not be released, as
MINA releases is automatically once a call is made to the IoSession
write() method.

Regards,
Donovan

Re: [mina] ByteBuffer allocation memory leak

Posted by Trustin Lee <tr...@gmail.com>.
Any news on this issue?

2005/7/14, Trustin Lee <tr...@gmail.com>:
> 
> Hi Donovan,
> 
> 2005/7/14, Donovan Du Plessis <do...@prism.co.za>:
> > 
> > e.g. ByteBuffer buffer_ = ByteBuffer.allocate(lengthOfPacket);
> > 
> 
> Do you call ByteBuffer.wrap() to wrap existing NIO buffer or byte array? 
> If so, it can cause memory leak. (Please see MINA ByteBuffer JavaDoc. You'll 
> have to call buffer_.acquire() once to prevent the leak.)
> 
> If not, all newly allocated ByteBuffers are released to internal MINA 
> ByteBufferPool. But it is not actually released, but hold by the pool 
> forever. So in the short term, it can be look like a memory leak, but the 
> usage of memory will not increase after sufficient amount of buffers are 
> pooled by the MINA. If OutOfMemoryError occurs, please try to increase 
> direct memory size of your VM like this:
> 
> java -XX:MaxDirectMemorySize=262144K ...
> 
> Please let me know the memory usage increases without limit even after 
> following the instruction above. And it would be nice if which type of 
> object is leaking.
> 
> Trustin
> -- 
> what we call human nature is actually human habit
> --
> http://gleamynode.net/ 



Trustin
-- 
what we call human nature is actually human habit
--
http://gleamynode.net/

Re: [mina] ByteBuffer allocation memory leak

Posted by Trustin Lee <tr...@gmail.com>.
Hi Donovan,

2005/7/14, Donovan Du Plessis <do...@prism.co.za>:
> 
> e.g. ByteBuffer buffer_ = ByteBuffer.allocate(lengthOfPacket);
> 

Do you call ByteBuffer.wrap() to wrap existing NIO buffer or byte array? If 
so, it can cause memory leak. (Please see MINA ByteBuffer JavaDoc. You'll 
have to call buffer_.acquire() once to prevent the leak.)

If not, all newly allocated ByteBuffers are released to internal MINA 
ByteBufferPool. But it is not actually released, but hold by the pool 
forever. So in the short term, it can be look like a memory leak, but the 
usage of memory will not increase after sufficient amount of buffers are 
pooled by the MINA. If OutOfMemoryError occurs, please try to increase 
direct memory size of your VM like this:

java -XX:MaxDirectMemorySize=262144K ...

Please let me know the memory usage increases without limit even after 
following the instruction above. And it would be nice if which type of 
object is leaking.

Trustin
-- 
what we call human nature is actually human habit
--
http://gleamynode.net/