title: Not closing a cursor can cause memory leaks?
body: <p>We are getting some memory leak problems. I think it should be because of the cursor, which is never closed. I'm sharing the parts where i think it is the source of the problem.</p>
  <pre><code>def execute_sql(sql):
      logs.custom_formatter(file_name=&quot;db&quot;, class_name=&quot;execute_sql&quot;)
      try:
          mycursor = cnx.cursor()
          print(&quot;sql:&quot;,sql)
          mycursor.execute(sql)
          result = mycursor.fetchall()
          return result
      except Exception as e:
          print(e)
          logs.info(&quot;Sql Select Error: {0}&quot;.format(e))
          return []
  </code></pre>
  <p>and this</p>
  <pre><code>def commit_sql(sql):
      logs.custom_formatter(file_name=&quot;db&quot;, class_name=&quot;commit_sql&quot;)
      try:
          mycursor = cnx.cursor()
          mycursor.execute(sql)
          cnx.commit()
          return True
      except Exception as e:
          logs.info(&quot;Sql Commit Error: {0}&quot;.format(e))
          return False
  </code></pre>
  <p>The functions above will be called for every user to check if they are already in database if so bring the infos of them otherwise insert them to the database. So you can assume that these functions are called frequently and after a while we observe that the respond time are increasing continuous so that we need to restart the code so it can be usable again.</p>
  <p>For now i have limited access to the code itself, but in a few days i will be given access to fix it and as far as i read from other sources i think it's probably the point, if we close the cursor, then it will be fine and memory leaks will be fixed.</p>
  <p>I'm asking you if this can be really a problem or i'm wrong and wasting my time struggling with the cursor thing.</p>