ByteBuffer.allocateView

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

ByteBuffer.allocateView

Oleksiy Stashok
Hello,

due to some problems, several emails where not delivered to the list.
So, I'm resending them.

From: bazi <[hidden email]>

Hey guys,

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.

best regards,
Piotr

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: ByteBuffer.allocateView

Oleksiy Stashok
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: [hidden email]
> For additional commands, e-mail: [hidden email]
>

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]