java@lists.mysql.com
[Top] [All Lists]

Re: Memory Leak

Subject: Re: Memory Leak
From: William Taylor
Date: Fri, 26 Feb 2010 00:40:29 -0800
On Feb 26, 2010, at 12:16 AM, Christopher G. Stach II wrote:

> 
> ----- "William Taylor" <williamt@xxxxxxxxxxxxxx> 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/java?unsub=mailarch@xxxxxxx

<Prev in Thread] Current Thread [Next in Thread>