I am designing a function (Java method) which will be executed 40-80 times per second on a mobile device.
I want to avoid producing a ton of dead variables which get collected by GC, as the function runs (possibly throughout the life of the app).
In C I might use volatile
for example, to prevent the memory allocation of my variables in each execution of the function... I want to do something similar in Java but don't know how.
The function stores data in
In general, in Java, what is the preferred method for using the above variables but not re-allocating them every time my function is executed (40+ times per second)?
Member variables would "work" but is this the best solution?
Thanks! Brad
Static member vars, they won't get unloaded until the class is unloaded. Keep in mind that if all references to the class are lost it is possible that it can be GC'ed. I doubt that will be an issue in your case however it is worth noting. In addition if you are creating new instances of the class containing the static members vars you will be in the same boat from an allocation stance.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With