Memroy leak with jdbc

Поиск
Список
Период
Сортировка
От Joseph Shraibman
Тема Memroy leak with jdbc
Дата
Msg-id 3EB6F489.8030901@selectacast.net
обсуждение исходный текст
Ответы Re: Memroy leak with jdbc
Re: Memroy leak with jdbc
Re: Memroy leak with jdbc
Список pgsql-jdbc
Using this test case with 9000 interations I get this output:

used: 474,296 free: 1,557,320 total: 2,031,616 max: 67,108,864
....................................................................................................
used: 4,646,760 free: 3,643,544 total: 8,290,304 max: 67,108,864
=================
used: 4,607,728 free: 3,682,576 total: 8,290,304 max: 67,108,864

I have no idea why this memory leak is happening. It only happens with this one select
statement, not all select statements.


/**
  * PostgresMemTest.java
  *
  *
  * Created: Mon May  5 18:40:29 2003
  *
  * @author <a href="mailto:jks@selectacast.net">Joseph Shraibman</a>
  * @version 1.0
  */
import java.sql.*;
public class PostgresMemTest {

  transient protected Connection  db;

     public PostgresMemTest(String url,String usr,String pwd) throws Exception{

         // try {
             // Load the driver
             Class.forName("org.postgresql.Driver");
             // } catch (ClassNotFoundException e){
             // e.printStackTrace();
             //return;
             //}
             // try{
             db = DriverManager.getConnection(url, usr, pwd);
             // } catch  (SQLException e){
             //e.printStackTrace();
             //return;
             // }
             Statement st = null;
             st = db.createStatement();
             st.executeUpdate("BEGIN;");
             st.executeUpdate("create temp table taba(pkey int, puindex int);");
             st.executeUpdate("create temp table tabpu(pukey int,  ukey int, pu text);");
             st.executeUpdate("create temp table tabu(ukey int, akey int);");
             st.executeUpdate("insert into taba values(1,2);");
             st.executeUpdate("insert into tabu values(3,1);");
             st.executeUpdate("insert into tabpu values(2,3,'blah');");

     } // PostgresMemTest constructor
     void doQuery() throws Exception{
         String line = null;
         //None of these remmed out lines produce the memory leak
         //line = "SELECT 'blah'";
         //line = "SELECT (SELECT 'blah');";
         //line = "select pu from tabpu where pukey = 2 and ukey = 3";
         line = "select (select pu from tabpu where pukey = taba.puindex and ukey =
tabu.ukey) from tabu where ukey = 3 and akey = 1;";
         Statement st = null;
         st = db.createStatement();
         ResultSet rs = st.executeQuery(line);

     }
     private static String uft(){
         Runtime rt = Runtime.getRuntime();
         long free = rt.freeMemory(), total = rt.totalMemory(), used =  total - free;
         long max = rt.maxMemory();
         long max2 = max - 67108864;

         java.text.NumberFormat nf = java.text.NumberFormat.getInstance() ;
         return "used: "+nf.format(used)+" free: "+nf.format(free)+
             " total: "+nf.format(total)+" max: "+nf.format(max2);
     }
     //Usage java PostgresMemTest <iterations> <url> <username> <passwd>
     public static void main(String args[])throws Exception{
         PostgresMemTest pmt = new PostgresMemTest(args[1],args[2],args[3]);
         System.out.println(uft());
         int times = Integer.parseInt(args[0]);
         final int perc = times/100;
         for(int i = 0; i < times; i++){
             pmt.doQuery();
             if (i % perc == 0){
                 System.out.print('.');
                 System.out.flush();
             }
         }
         System.out.println();
         System.out.println(uft());
         System.gc();
         System.gc();
         System.gc();
         System.out.println("=================");
         System.out.println(uft());

     }
} // PostgresMemTest




--
Joseph Shraibman
joseph@xtenit.com
Increase signal to noise ratio.  http://xis.xtenit.com


В списке pgsql-jdbc по дате отправления:

Предыдущее
От: Devrim GUNDUZ
Дата:
Сообщение: Memory footprint for a single connection
Следующее
От: Joseph Shraibman
Дата:
Сообщение: Re: Memroy leak with jdbc