I am working on an Android application, and the method I am writing can be called a bunch of times. In this method, I am making updates to the user interface. Memory and performance are important to me. As I see it, I have 2 options for changing the user interface.
The first is to create 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 refer to it in the method. It might look like this:
View myView = new View();
public void myMethod(){
myView.makeVisible();
}
Obviously, if this method is called only a few times, any difference will be small. However, if I potentially call it many times, and there are many variables called / created in this way, does the second way increase performance?