Creation of 1.Java performance optimization objects
For every Java programmer knows how to create objects, but do you know how to create them to improve the performance of your application?
Do you know the application rules for creating objects?
(1). To avoid creating objects in the loop body as much as possible .
(2). Try to make the object conform to the garbage collection standard in time.
(3). Do not take too deep an inheritance level.
(4). Accessing local variables is better than accessing variables in the class.
For example:
Vector v=new vector ();
for (int i=0; i<100;i++) {
Object Obj=new object ();
}
This kind of writing is not strange to everyone. But this will waste a lot of memory space. The correct method is as follows.
Vector v=new vector ();
Object Obj=null;
for (int i=0; i<100;i++) {
Obj=new Object ();
}
This saves a reference to an object in memory, thereby reducing the amount of memory space wasted.
And also:
Do not initialize an object more than once. This also leads to significant memory overhead, which offsets system performance.
public class Test () {
Private HashMap map=new HashMap ();
Public Test () {
Map=new HashMap ()
}
}
The above points are well understood. But there are a lot of novice will appear above the problem Oh!!!!
Working: Creating objects for Java performance optimization