users@grizzly.java.net

Re: ByteBuffer.allocateView

From: Oleksiy Stashok <Oleksiy.Stashok_at_Sun.COM>
Date: Mon, 07 Jan 2008 16:44:54 +0100

Hi Piotr,

> I've been developing an application using your framework for some time
> and one thing has just hit my mind. Within the last release you've
> added functionality of asynchronous queues. Here comes a question.
> In the TCPAsyncQueueWriter write method implementation if
> isCloneByteBuffer is set to true ByteBuffer.allocateView is called to
> create a copy. It's flushed one time when it's ready and then removed
> from the queue. But there is no way to tell the preallocated buffer
> that the slice is not in use anymore. It leads to kinda 'memory leak'
> as this memory cannot be neither reused nor gc'ed. Let me know if I
> missed something here.
Currently there is no way to release ByteBuffer.

Also think, using isCloneBuffer as true, it's just easy way how
developer can send bytes using AsyncQueue and not care about buffers.
If you need better memory control I would suggest to not use cloning,
but perform all the required memory operations in code. For example:

1) take ByteBuffer from memory pool
2) fill it with data
3) Call AsyncQueue send method with clone=false and register callback
handler, which will be called once bytebuffer data will be sent
4) When callbackHandler.onWriteCompleted is called - return ByteBuffer
to the memory pool.

Hope this will help.

WBR,
Alexey.
>
> best regards,
> Piotr
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_grizzly.dev.java.net
> For additional commands, e-mail: users-help_at_grizzly.dev.java.net
>