Several ways to avoid memory leaks in Java are as follows:
Release the session when it is no longer needed. Use the HttpSession.invalidate() to do this.
Keep the time-out time low for each session.
Store only the necessary data in your HttpSession.
Avoid using string concatenation. Use StringBuffer’s append() method because the string is an unchangeable object while string concatenation creates a lot of unnecessary objects. A large number of temporary objects will slow down performance.
As much as possible, you should not create HttpSession on your JSP page. You can do this by using the page directive <%@page session=” false”%>.
If you are writing a query that is frequently executed, use the PreparedStatement object rather than using the Statement object. Why? PreparedStatement is precompiled while Statement is compiled every time your SQL statement is transmitted to the database.
When using JDBC code, avoid using “*” when you write your query. Try to use the corresponding column name instead.
If you are going to use stmt = con.prepareStatement(SQL query) within a loop, then be sure to close it inside that particular loop.
Be sure to close the Statement and ResultSet when you need to reuse these.
Close the ResultSet, Connection, PreparedStatement, and Statement in the finally block.
Abstraction is basically used to separate the useless data from the essential ones. Only the important things that need to be shown to the users are only being exposed. Here in these issues, the users...