We mistakenly assumed that JNI's Get<Primitive>ArrayElements returned a local reference or was somehow tracked such that when the JNI method returned, the array would automatically be cleaned up. This is not the case, which seems reasonable since the return type of the method is a native array pointer.
This change switches to using a unique pointer with a custom deleter to hold the result of each Get<Primitive>ArrayElements call.
The custom deleter calls Release<Primitive>ArrayElements.
Validation performed
Validated unit tests passed.
Encoded millions of messages and verified memory usage stops growing after a few GB (1.5 on my machine).
References
26
Description
Get<Primitive>ArrayElements
returned a local reference or was somehow tracked such that when the JNI method returned, the array would automatically be cleaned up. This is not the case, which seems reasonable since the return type of the method is a native array pointer.Get<Primitive>ArrayElements
call.Release<Primitive>ArrayElements
.Validation performed