ByteBuffer.wrap(byte )是否会导致长时间运行的应用程序出现内存泄漏?

我试图在线搜索,但没有找到答案。

基于java doc ,ByteBuffer.wrap()在每次调用中创建一个新的ByteBuffer。 在长时间运行的应用程序中,如果未触发gc,但应用程序一直在调用ByteBuffer.wrap(),则应用程序可能会在Java堆外部使用更多内存,并导致潜在的内存泄漏。 是对的吗?

public static ByteBuffer wrap(byte[] array) Wraps a byte array into a buffer. The new buffer will be backed by the given byte array; that is, modifications to the buffer will cause the array to be modified and vice versa. The new buffer's capacity and limit will be array.length, its position will be zero, and its mark will be undefined. Its backing array will be the given array, and its array offset will be zero. 

基于jdk代码,似乎答案是否定的,因为ByteBuffer.wrap()创建了一个新的HeapByteBuffer对象,但没有在下面分配新的缓冲区。

 public static ByteBuffer wrap(byte[] array, int offset, int length) { try { return new HeapByteBuffer(array, offset, length); } catch (IllegalArgumentException x) { throw new IndexOutOfBoundsException(); } } 

如果要保留数组的硬引用或包装ByteBuffers,那么这只是一个问题。

“wrap”方法不会像直接ByteBuffer那样在堆外部分配内存。 垃圾收集器应该能够在发生OutOfMemory错误之前将其清理干净。