mirror of
https://github.com/google/flatbuffers.git
synced 2026-06-02 04:04:19 +00:00
Adds __reset method to Struct and Table (#4966)
This allow recycling/pooling instances without leaking ByteBuffers, by providing a mechanism to reset instance to newly constructed state.
This commit is contained in:
committed by
Wouter van Oortmerssen
parent
7a43775661
commit
f85af46262
@@ -28,6 +28,20 @@ public class Struct {
|
||||
protected int bb_pos;
|
||||
/** The underlying ByteBuffer to hold the data of the Struct. */
|
||||
protected ByteBuffer bb;
|
||||
|
||||
/**
|
||||
* Resets internal state with a null {@code ByteBuffer} and a zero position.
|
||||
*
|
||||
* This method exists primarily to allow recycling Struct instances without risking memory leaks
|
||||
* due to {@code ByteBuffer} references. The instance will be unusable until it is assigned
|
||||
* again to a {@code ByteBuffer}.
|
||||
*
|
||||
* @param struct the instance to reset to initial state
|
||||
*/
|
||||
public void __reset() {
|
||||
bb = null;
|
||||
bb_pos = 0;
|
||||
}
|
||||
}
|
||||
|
||||
/// @endcond
|
||||
|
||||
@@ -292,6 +292,18 @@ public class Table {
|
||||
}
|
||||
return len_1 - len_2;
|
||||
}
|
||||
|
||||
/**
|
||||
* Resets the internal state with a null {@code ByteBuffer} and a zero position.
|
||||
*
|
||||
* This method exists primarily to allow recycling Table instances without risking memory leaks
|
||||
* due to {@code ByteBuffer} references. The instance will be unusable until it is assigned
|
||||
* again to a {@code ByteBuffer}.
|
||||
*/
|
||||
public void __reset() {
|
||||
bb = null;
|
||||
bb_pos = 0;
|
||||
}
|
||||
}
|
||||
|
||||
/// @endcond
|
||||
|
||||
Reference in New Issue
Block a user