dev@grizzly.java.net

Re: buffer dispose question

From: Tigran Mkrtchyan <tigran.mkrtchyan_at_desy.de>
Date: Thu, 22 Mar 2012 16:32:30 +0100

Hi Alexey,

On Thu, Mar 22, 2012 at 4:17 PM, Oleksiy Stashok
<oleksiy.stashok_at_oracle.com> wrote:
> Hi Tigran,
>
> we'll probably need to introduce another allowBufferDispose method in
> CompositeBuffer, which will propagate the dispose flag to underlying
> Buffers.
>
> Now when you dispose CompositeBuffer, if its allowInternalBuffersDispose
> flag is true, it iterates over all the internal Buffers and calls
> internalBuffer.tryDispose(). So it's up to each internal Buffer to decide if
> it wants to be disposed or not.

This is OK if you know that buffer is composite, But I don't (well I
can always ask isComposite).

       Buffer buffer = xdr.body();
       buffer.allowBufferDispose(true);
        _context.write(_context.getAddress(), buffer, null);

buffer can be CompositeBuffer of HeapBuffer. This is what grzzly gives
me depending on does message arrived at once or in multiple chinks.

Other question:

In case a buffer is not disposed do I get memory leak or it will be GC
and allocated a new one?

Tigran.

>
> Specifically for CompositeBuffer, allowBufferDispose means whether this
> CompositeBuffer instance will or will not be returned to a thread-local
> object cache after CompositeBuffer.tryDispose is called.
>
> Thanks.
>
> WBR,
> Alexey.
>
>
> On 03/22/2012 04:03 PM, Tigran Mkrtchyan wrote:
>>
>> test case attached
>>
>> On Thu, Mar 22, 2012 at 3:43 PM, Tigran Mkrtchyan
>> <tigran.mkrtchyan_at_desy.de>  wrote:
>>>
>>> Hi,
>>>
>>> I have a following code:
>>>
>>> Buffer buffer1 = ...;
>>> Buffer buffer2 = ...;
>>>
>>>  Buffer composite =
>>> BuffersBuffer.create(MemoryManager.DEFAULT_MEMORY_MANAGER,
>>>                buffer1, buffer2 );
>>>  composite.allowBufferDispose(true);
>>>
>>> At this point I expect that
>>>
>>> composite.tryDispose() and composite.dispose() will dispose buffer1 and
>>> buffer2.
>>>
>>> Nevertheless this is not the case. I think
>>>
>>> composite.allowBufferDispose(true);
>>>
>>> have to propagate to  buffer1 and buffer2 or
>>>
>>> BuffersBuffer.removeAndDisposeBuffers  have to call dispose on
>>> underlying buffers instead of tryDispose.
>>>
>>> Tigran.
>
>