title: How to free memory after fetching data via jdbc
body: <p>i am using spring jdbc on weblogic. And i set fetch size to 500 for fetching data from db more faster. But this causes memory problems. Here is an example:</p>
  
  <p><a href="http://webmoli.com/2009/02/01/jdbc-performance-tuning-with-optimal-fetch-size/" rel="nofollow">http://webmoli.com/2009/02/01/jdbc-performance-tuning-with-optimal-fetch-size/</a></p>
  
  <p>My question is how to free this memory? Running GC is not working, I guess it is not working because of connection is alive in the connection pool.</p>
  
  <p>Code:</p>
  
  <pre><code>public List&lt;Msisdn&gt; getNewMsisdnsForBulkSmsId(String bulkSmsId,String scheduleId,final int msisdnCount) throws SQLException {
              JdbcTemplate jdbcTemplate = getJdbcTemplate();
              jdbcTemplate.setFetchSize(500);
              jdbcTemplate.setMaxRows(msisdnCount);
              jdbcTemplate.query("select BULKSMS_ID, ? as , STATUSSELECTDATE, DELIVERYTIME, ID, MESSAGE from ada_msisdn partition (ID_"+bulkSmsId+") where bulksms_id = ? and status = 0 and ERRORCODE = 0 and  SCHEDULEID is null for update skip locked", new Object[]{scheduleId,bulkSmsId}, MsisdnRowMapper.INSTANCE);
  
    //Also i tried to close connection and run gc, this does not free the memory too.
              //jdbcTemplate.getDataSource().getConnection().close();
              //System.gc();
  
              return null;
  }
  </code></pre>
  
  <p>when i set fetch size to 10, heap size is  12 MB
  if i set fetch size to 500, heap size is 206 MB</p>
  
  <p>Thanx</p>