Question regarding refcount of ByteBuf in our client API
- Dominant language
- Java
- Stars
- 2k
- Forks
- 976
- Avg merge
- 6d 15h
- Merged PRs (30d)
- 7
Description
**QUESTION**
Regarding the refcount of ByteBuf, from what I understand the API method which takes ByteBuf as argument shouldn't increase or decrease the refcount of 'ReferenceCounted' object.
I mean
```
myApplicationMethod() {
ByteBuf byteBuf = createNewInstanceOfByteBuf();
...
APIClass.APIMethod(bytebuf);
...
byteBuf.release();
}
```
here when I create byteBuf the refCount would typically be 1. Now by passing this refcounted object to the standard API method, I don’t expect the APIMethod to decrease the refCount (modify refCount) and finally it is the responsibility of the caller (application) method to release it by calling release method explicitly when they are done with the byteBuf.
But in our case WriteAdvHandle.write(long entryId, ByteBuf data) is decreasing the refcount, this is because of https://github.com/apache/bookkeeper/blob/master/bookkeeper-server/src/main/java/org/apache/bookkeeper/client/PendingAddOp.java#L422 .
**Que:** Why are we doing this? What is the general practice with regards to usage of refcounted objects in API methods? Have we mentioned the expected behavior in detail in our API docs?
Are we doing corresponding release calls in all the places where ByteBuff is created. https://netty.io/4.0/api/io/netty/util/ReferenceCounted.html says that initial count would be 1 when an ReferenceCounted object is created.
Are there enough documentation/comments in code/invariant checks/testcases at each layer for ByteBuf usage in our Client and Server code?
Contributor guide
Assessment
This issue has not been assessed yet.