I'm using android sensors, and I don't want my code to produce a new object for each sensor event. For now, I'm copying the values contained in the array SensorEvent.values
to my own Sample
class values array.
I know SensorEvent
s are reused by the system and cannot be kept, but I was wondering if SensorEvent.values
was also reused or if a new array was allocated. Indeed, there is no point in copying the array into mine if a new is created anyway (I'd better replace my own array by SensorEvent.values
directly).
I've been looking at different posts like post 1 and post 2 but they deal with SensorEvent
objects and not the values
field itself.
To clarify for future readers, the array SensorEvent.values
is reused as well as the SensorEvent
object. Therefore, one should not keep any reference to it, and should instead copy each value.