Skip to Content

Archived discussions are read-only. Learn more about SAP Q&A

Possible of memory leak in the loop

Recently my application do get OutOfMemory issue. I realized the memory is keep on stack up as i saw in the task manager, the jlaunch keep growing and it won't drop back. That day i'm running a search function and it will query the table to retrieve the data. The jlaunch shoot from 500MB -> 2.2GB and now remain in there. Wondering is it during it query it populate at least 10,000 records into the arraylist and then the memory already allocated and once i finish run the function, it will clear the allocated memory to re-use it.

public ArrayList ejbHomeInJDBCConnection(Map map){
	ArrayList beanList = new ArrayList();
		Context ctx = new InitialContext();
		DataSource ds = (DataSource) ctx.lookup("jdbc/POOL");
		Connection con = ds.getConnection();
		String query = "SELECT * FROM USER WHERE ";
		for (Iterator iterator = map.keySet().iterator(); iterator.hasNext();) {
			Object key =;
			if(key.toString().startsWith("TIME") | key.toString().startsWith("TIMEIN")){
				long longValue = Long.parseLong(map.get(key).toString());
				query += key.toString()+ longValue + " AND "; 	
				String value = (String)map.get(key);
				query += key.toString()+ value + " AND "; 	
		String newquery = query.substring(0, query.length()-5);
		newquery += " ORDER BY TIMEIN DESC";
		Statement stmt = con.createStatement();
		try {
			ResultSet rs = stmt.executeQuery(newquery);
		    try {
				while ({
					InBean bean = new InBean();
	}catch(Exception e){
return beanList;

Wondering is it the InBean will cause any memory leak as if there is 10,000 records, which mean it will create 10,000 objects and once it add into the arraylist the previous bean is not in use, will the GC clear it as i didn't set it as null. Do i need to do something like reallocate/defragment the memory?


Former Member

Helpful Answer

Not what you were looking for? View more on this topic or Ask a question