I have few questions about efficient memory usage. I have a form which will be submitted to receive a list of items as result. Once form is submitted its fields will be received by request variable and will be processed by submitRequest
method of model class.
Question is that where should I allocate memory to request variable (Request request = new Request
) ? in constructor? or do not allocate it at all as it works now?
Second question is that where should I make an object of Model
class as it is being used by different methods. Should I define it in each method or it is better to have a single object of it?
public class MyClass{
private Request request;
private List<result> results;
//private formModel myModel = new formModel();
public MyClass(){
}
public String myForm(){
formModel myModel = new formModel();
this.results = myModel.submitRequest(request); //process request and return results
return "SUCCESS";
}
.......
}