Closed jimrthy closed 7 years ago
Any attempt to coerce a Netty ByteBuf
into a different representation will release it. The coercion for print-bytes
doesn't know it's coercing for debugging purposes, so it does what is done everywhere else. I can add this as documentation in Aleph, but maybe you could help me understand what your expected behavior is here.
After I read some more and slept on it, I think the real problem was my lack of understanding about the way ByteBuf and reference counting work.
I think my basic thought process was something along the lines of "Why would it call .release()? Surely it doesn't think I'm really handing over control/responsibility."
It seems like it might be worth adding some sort of warning to the docs, possibly even with a link to somewhere like https://github.com/netty/netty/wiki/Reference-counted-objects. But maybe not...I'm sure I ran across that link and never bothered to actually read it until I ran into this.
I'm sorry for wasting your time. Thanks for a great library!
(let [buf (Unpooled/buffer 4)] (.writeInt buf 42) (println "Ref: " (.refCnt buf)) (bs/print-bytes buf) (println "Ref: " (.refCnt buf)))
=> Ref: 1 00 00 00 2A Ref: 0
This may be deliberate, but I really expected the refCnt to remain unchanged.
If nothing else, it seems worth documenting.