title: Java memory leak caused by MySQL libraries
body: <p>I have a thread that executes and updates a database with some values. I commented out all the operations done to the data and just left the lines you can see below. While running the program with the lines you see bellow I get a memory leak.</p>
  <p>This is what it looks like in VisualVM</p>
  <p><img src="https://i.stack.imgur.com/Vbcym.png" alt="enter image description here" />
  <img src="https://i.stack.imgur.com/eerGu.png" alt="enter image description here" />
  Mysql Class</p>
  <pre><code>    public ResultSet executeQuery(String Query) throws SQLException {
          statement = this.connection.createStatement();
          resultSet = statement.executeQuery(Query);
          return resultSet;
  
      }
  
  
  
      public void executeUpdate(String Query) throws SQLException {
          Statement tmpStatement = this.connection.createStatement();
          
          tmpStatement.executeUpdate(Query);
          tmpStatement.close();
          tmpStatement=null;
          
      }
  </code></pre>
  <p>Thread file</p>
  <pre><code>public void run() {
          ResultSet results;
          String query;
          int id;
          String IP;
          int port;
          String SearchTerm;
          int sleepTime;
          while (true) {
              try {
  
                  query = &quot;SELECT * FROM example WHERE a='0'&quot;;
                  results = this.database.executeQuery(query);
  
                  while (results.next()) {
                      
                      id = results.getInt(&quot;id&quot;);
                  
                      query = &quot;UPDATE example SET a='1' WHERE id='&quot;
                              + id + &quot;'&quot;;
                      SearchTerm=null;
                      this.database.executeUpdate(query);
                  }
                  results.close();
                  results = null;
                  
              } catch (Exception e) {
                  // TODO Auto-generated catch block
                  e.printStackTrace();
              }
          }
  
      }
  </code></pre>
  <p>The problem has happened with many other people after researching the web,</p>
  <p><a href="https://forum.hibernate.org/viewtopic.php?f=1&amp;t=987128" rel="nofollow noreferrer">https://forum.hibernate.org/viewtopic.php?f=1&amp;t=987128</a></p>
  <p><a href="https://stackoverflow.com/questions/17480639/is-bone-cp-or-mysql-jdbc-jdbc4connection-known-for-leaking">Is bone cp or mysql.jdbc.JDBC4Connection known for leaking?</a></p>
  <p>and a few more if you google &quot;jdbc4resultset memory leak&quot;</p>