You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@mina.apache.org by Michael Bauroth <mi...@falcom.de> on 2006/07/04 11:59:14 UTC

Memory leak?

Hi,

I've attached a method from a simple TCP client, which only writes 
continously data to a server. Unfortunately over the time the memory 
consumption increases continously too. I will check the whole thing with 
JProbe now, but maybe someone has an idea before?!

public void writeProtocol( IoSession pSession, int pCounter )  {
     ByteBuffer tWriteBuffer = ByteBuffer.wrap(("aaa\r\n" +
	"aaa\r\n" +
	"aaa\r\n" +
	"aaa\r\n" + pCounter + ">\r\n").getBytes());
     	
     tWriteBuffer.acquire();
     pSession.write( tWriteBuffer );
     tWriteBuffer.release();
}

When I use ByteBuffer.setUseDirectBuffers( true ), the memory leak 
occurs, if I use ByteBuffer.setUseDirectBuffers( false ) instead, the 
app works without memory leak. On the server side (same computer) I use 
direct buffers all the time!

Regards
Michael



Re: Memory leak?

Posted by peter royal <pr...@apache.org>.
On Jul 4, 2006, at 5:59 AM, Michael Bauroth wrote:
> I've attached a method from a simple TCP client, which only writes  
> continously data to a server. Unfortunately over the time the  
> memory consumption increases continously too. I will check the  
> whole thing with JProbe now, but maybe someone has an idea before?!
>
> public void writeProtocol( IoSession pSession, int pCounter )  {
>     ByteBuffer tWriteBuffer = ByteBuffer.wrap(("aaa\r\n" +
> 	"aaa\r\n" +
> 	"aaa\r\n" +
> 	"aaa\r\n" + pCounter + ">\r\n").getBytes());
>     	
>     tWriteBuffer.acquire();
>     pSession.write( tWriteBuffer );
>     tWriteBuffer.release();
> }
>
> When I use ByteBuffer.setUseDirectBuffers( true ), the memory leak  
> occurs, if I use ByteBuffer.setUseDirectBuffers( false ) instead,  
> the app works without memory leak. On the server side (same  
> computer) I use direct buffers all the time!

The acquire() / release() cycle isn't needed in this case, since  
you're wrapping your own byte[].

I'd be interested as to the results of your run with JProbe. I've  
also had very good success tracking down memory leaks using http:// 
yourkit.com profiler.

-pete




-- 
proyal@apache.org - http://fotap.org/~osi