which is better performance, using a disposable local variable or reusing a global one?
- by petervaz
This is for an android game.
Suppose I have a function that is called several times for second and do some calculations involving an arraylist (or any other complex objects for what matter).
Which approach would be preffered?
local:
private void doStuff(){
ArrayList<Type> XList = new ArrayList<Type>();
// do stuff with list
}
global:
private ArrayList<Type> XList = new ArrayList<Type>();
private void doStuff(){
XList.clear();
// do stuff with list
}