Thread: JDBC memory leak?

Results 1 to 7 of 7
  1. #1 JDBC memory leak? 
    Registered Member
    Join Date
    Nov 2007
    Posts
    81
    Thanks given
    1
    Thanks received
    9
    Rep Power
    22
    i'd post in the java section but that seems to be a pretty dead section.. anyways

    i use my own code for JDBC execution so it doesn't exist anywhere else. anyway, after a few hours memory usage for MySQL/JDBC spikes to 100mb+ and slowly rises.. ;-;

    I use PreparedStatements, I clear them after I execute them, and I close them, too, including any queries I do with ResultSets..


    anything I'm missing? this is the general block of code executed for inserting:
    Code:
    			final PreparedStatement p = con.prepareStatement("INSERT INTO `bans` SET `trigger` = ? -- etc...");
    			p.setString(1, "lols");
    			p.executeUpdate();
    			p.clearParameters();
    			p.close();
    if you want examples of how other things are done, just ask..

    also queries are executed very often, so it adds up quite fast.. I will try some things in the next few minutes to get code that rapidly reproduces the leak.
    Reply With Quote  
     

  2. #2  
     

    Vastiko's Avatar
    Join Date
    Dec 2006
    Posts
    5,700
    Thanks given
    300
    Thanks received
    663
    Rep Power
    5000
    Ive never heard of the JDBC memory leaking before, I just googled it and there werent many reports on this, there were a few but it doesn't seem common.

    Try asking someone very experienced in the MySQL language to look over your statements, it maybe your missing something.

    I am not however so I wouldn't even know where to begin!

    Hope you get some help soon though
    Reply With Quote  
     

  3. #3  
    Registered Member
    Join Date
    Nov 2007
    Posts
    81
    Thanks given
    1
    Thanks received
    9
    Rep Power
    22
    Odd. I could reproduce it easily with:

    Code:
    				for(int i=0; i<100; i++) {
    					java.sql.ResultSet rs = Server.getServer().getMySQL().executeQuery("SELECT * FROM `bans`");
    					try {
    						while(rs.next()) {
    							
    						}
    						rs.close();
    					} catch (SQLException e) {
    						e.printStackTrace();
    					}
    				}
    What was I missing? closing the statement. However, all of my calls to ResultSet DO close the statement.. so I figured, it'd be how I insert logs, or players.. The above without closing the statement, using 500,000 iterations. With the memory leak, memory usage would quickly run the JVM OOM. With closing the statement in the above statement, the leak is no longer present.

    So then, what about the PreparedStatements? No.. I tried inserting logs for 500,000 iterations. It didn't make the memory go up at all after it was completed.


    so.. the hell? :\
    Reply With Quote  
     

  4. #4  
    Registered Member

    Join Date
    Aug 2007
    Posts
    2,395
    Thanks given
    2
    Thanks received
    63
    Rep Power
    558
    Do you call System.gc(); ?
    Reply With Quote  
     

  5. #5  
    Registered Member
    Join Date
    Nov 2007
    Posts
    81
    Thanks given
    1
    Thanks received
    9
    Rep Power
    22
    Once on startup after loading, after that? No. Calling it manually does nothing. It makes memory go down for a second then it's back to what it used to be.
    Reply With Quote  
     

  6. #6  
    Renown Programmer

    Join Date
    Dec 2008
    Posts
    363
    Thanks given
    1
    Thanks received
    28
    Rep Power
    99
    MySQL or JDBC is using a lot of memory? Whichever, if you think you've found a problem, file a bug report or discuss in the mailing list upstream.
    Reply With Quote  
     

  7. #7  
    Banned

    Join Date
    Jul 2008
    Age
    28
    Posts
    5,827
    Thanks given
    1,301
    Thanks received
    197
    Rep Power
    0
    Quote Originally Posted by Hidendra_ View Post
    Once on startup after loading, after that? No. Calling it manually does nothing. It makes memory go down for a second then it's back to what it used to be.
    Untrue, call it every time you call close() if its not time critical.
    Reply With Quote  
     


Thread Information
Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)


User Tag List

Posting Permissions
  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •