I am working on an Android app and a method I am writing might get called a bunch of times. In this method I am making updates to the user interface. Memory use and performance are important to me. The way I see it, I have 2 options for making the UI changes.
The first is to makes new objects every time. That is to say something like:
public void myMethod(){
new View().makeVisible();
}
The second is to declare the object as a variable globally and reference it in the method. This might look like:
View myView = new View();
public void myMethod(){
myView.makeVisible();
}
Obviously the if this method only called a few times any difference is going to be small. However if I am potentially calling this many times, and there are many variables being call/or created this way, does the second way increase performance?