Re: Memroy leak with jdbc - Mailing list pgsql-jdbc
From | Barry Lind |
---|---|
Subject | Re: Memroy leak with jdbc |
Date | |
Msg-id | 3EB70B54.5000702@xythos.com Whole thread Raw |
In response to | Memroy leak with jdbc (Joseph Shraibman <jks@selectacast.net>) |
Responses |
Re: Memroy leak with jdbc
|
List | pgsql-jdbc |
Joseph, The reason this is happening is because this particular select statement is generating a warning message from the server. If you turn on logging in the driver (add ?loglevel=2 to the jdbc URL) you will see the following warning generated for each execution of this sql statement: NOTICE: Adding missing FROM-clause entry in subquery for table "taba" These warning messages are stored up until you read them, or call clearWarnings(). This is all correct behavior AFAICT. thanks, --Barry Joseph Shraibman wrote: > 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 > > > >
pgsql-jdbc by date: