Re: Memory Leak
William Taylor <[email protected]> Fri, 26 Feb 2010 00:40:29 -0800
| Newsgroups | gmane.comp.db.mysql.java |
|---|---|
| Message-ID | <[email protected]> |
On Feb 26, 2010, at 12:16 AM, Christopher G. Stach II wrote: >=20 > ----- "William Taylor" <[email protected]> wrote: >=20 >> On Feb 25, 2010, at 11:44 PM, Christopher G. Stach II wrote: >>>> Working on some code where I select 4 million rows and store the >>>> results in a short array. >>>=20 Here is the test case. This is with the newest connector J 5.1.12 table name is test with a single smallint column. 4 million rows. first console output shows 0mb used by the problem. each output after that shows ~255MB of ram used. regardless of how long you let the program run the GC never reclaims the = memory. top says java is using ~289MB ram. mysqld shows ~7.4mb ram public class Test { public static void main(String[] args)=20 { new Test(); } =20 public Test() { System.out.println((Runtime.getRuntime().totalMemory() - = Runtime.getRuntime().freeMemory())/(1024*1024)+" MB"); =20 try=20 { Class.forName("com.mysql.jdbc.Driver").newInstance(); = =20 }=20 catch (InstantiationException e)=20 { e.printStackTrace(); =20 }=20 catch (IllegalAccessException e)=20 { e.printStackTrace(); =20 }=20 catch (ClassNotFoundException e)=20 { e.printStackTrace(); System.exit(1); =20 } =20 try { =20 String url =3D = "jdbc:mysql://localhost/yourDataBase";//?dontTrackOpenResources=3Dtrue"; String userName =3D "username"; String password =3D "password"; =20 Connection connection =3D DriverManager.getConnection (url, = userName, password); PreparedStatement statement =3D = connection.prepareStatement("select id from test"); ResultSet resultSet =3D statement.executeQuery(); =20 =20 resultSet.close(); =20 statement.close(); connection.close(); } catch (SQLException e) { e.printStackTrace(); } =20 =20 while(true) { try { Thread.sleep(1000); } catch (InterruptedException e) { e.printStackTrace(); } =20 System.out.println((Runtime.getRuntime().totalMemory() - = Runtime.getRuntime().freeMemory())/(1024*1024)+" MB"); } } }= -- MySQL Java Mailing List For list archives: http://lists.mysql.com/java To unsubscribe: http://lists.mysql.com/[email protected]