Are Java DirectByteBuffer wrappers garbage collected?

后端 未结 4 731
灰色年华
灰色年华 2020-12-08 05:52

I understand that when a directbytebuffer is allocated, its not subject to garbage collection, but what I\'m wondering is if the wrapping object is garbage collecte

4条回答
  •  醉酒成梦
    2020-12-08 06:24

    Looking at the source code to DirectByteBuffer it just returns a new instance, so no, you won't OOM yourself.

    As long as the rest of your code doesn't hold onto a reference to the original dbb then that object will get garbage collected as normal. The extra dbb2 objects will similarly get garbage collected when there is no longer any reference to them(ie, the end of the while loop).

提交回复
热议问题