A Java memory leak is divided into two main areas:
(1) The space requested in the heap has not been released.
(2) The object is no longer in use, but still exists in memory
The following concentration conditions can cause a memory leak
(1) Static collection using HashMap and vectors, the life cycle of the static container is consistent with the program, then the container will not be released before the end of the program, resulting in a memory leak;
Like what:
Vector v=new vector ()for (int i=0;i<10;i++) {object o=new object (); V.add (o);}
o objects are no longer needed, but cannot be recycled
(2) Various connection problems: Database connection and IO connection, need to call the Close method to release the connection, such as connection, statement, resultset
(3) Use of the listener
(4) Irrational scope of variables
1) The scope of a variable definition is greater than the scope of its use:
The scope of use of MSGD should be in the aspect
Class server{private string msg; void//// input db }}
2) The object is not set to NULL in time
or set MSG to NULL after use
(5) Use of single-case mode
class bigclass{..... }classsingleton{Private bigclass BC, ......... }//BC objects cannot be recycled
The garbage collection algorithm has
(1) Reference counting algorithm
(2) Tracking recovery algorithm, reference diagram
(3) Compression recovery algorithm
(4) Replication recovery algorithm
(5) Recycling algorithm by generation
Java memory leaks