Chapter 6. Recycling Regardless of continuous improvements in
Chapter 6. Recycling Regardless of continuous improvements in memory management speed, allocating and eventually discarding objects (via garbage collection) will always impose a nontrivial performance cost on Java programs. Moreover, object creation itself imposes an additional cost of properly setting the initial state of the constructed object via a constructor invocation. Object construction triggers the following steps [LY97]: . Sufficient memory is allocated to hold all instance variables (object members) as well as those of each superclass. . All instance variables of this class and those of each superclass are initialized to their default values (numeric variables to 0, boolean to false, reference types to null.) . Proper values are assigned to the constructor arguments. . If the constructor starts with an explicit invocation of another constructor of the same class (using this), then that constructor is invoked after evaluation of its arguments. . Otherwise, implicitly or explicitly, the superclass constructor (super) is invoked after evaluation of its arguments, if any. . Instance variable initializers are executed for this class as they appear in the source code. . The rest of the constructor body is executed. As you can tell, object creation can get expensive very quickly. The cost is proportional to the number of instance variables, the depth of the inheritance chain for the constructed class instance itself, as well as to the complexity of any member object references that are initialized to anything other than null. The least expensive objects are those that are never constructed. This chapter presents a few optimizations that try to circumvent the whole issue of object construction and destruction by recycling old ones. Page 136
Note: If you are looking for cheapest and affordable webspace to host and run your servlet application check Astra servlet hosting services