Re: Memory Leak
Ronald Klop <[email protected]> Fri, 26 Feb 2010 13:45:58 +0100 (CET)
| Newsgroups | gmane.comp.db.mysql.java |
|---|---|
| Message-ID | <1355258871.770.1267188358956.JavaMail.tomcat@localhost> |
------=_Part_769_926675542.1267188358949 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit Can you put System.gc() before or after the sleep? The GC wil not run if you don't need the memory for something else. Ronald. Op vrijdag, 26 februari 2010 09:40 schreef William Taylor <[email protected]>: > > > > On Feb 26, 2010, at 12:16 AM, Christopher G. Stach II wrote: > > > > > ----- "William Taylor" <[email protected]> wrote: > > > >> 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. > >>> > > > 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) > { > new Test(); > } > > public Test() > { > System.out.println((Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory())/(1024*1024)+" MB"); > > try > { > Class.forName("com.mysql.jdbc.Driver").newInstance(); > } > catch (InstantiationException e) > { > e.printStackTrace(); > } > catch (IllegalAccessException e) > { > e.printStackTrace(); > } > catch (ClassNotFoundException e) > { > e.printStackTrace(); > System.exit(1); > } > > try > { > String url = "jdbc:mysql://localhost/yourDataBase";//?dontTrackOpenResources=true"; > String userName = "username"; > String password = "password"; > > Connection connection = DriverManager.getConnection (url, userName, password); > PreparedStatement statement = connection.prepareStatement("select id from test"); > ResultSet resultSet = statement.executeQuery(); > > resultSet.close(); > statement.close(); > connection.close(); > } > catch (SQLException e) > { > e.printStackTrace(); > } > > while(true) > { > try > { > Thread.sleep(1000); > } > catch (InterruptedException e) > { > e.printStackTrace(); > } > > 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] > > > > ------=_Part_769_926675542.1267188358949--