<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <meta content="text/html; charset=ISO-8859-1"
      http-equiv="Content-Type">
  </head>
  <body text="#000000" bgcolor="#ffffff">
    Hi,<br>
    <br>
    I've never seen memleaks on luasql using the following code:<br>
    <br>
    Feel free to use it and modify/improve ;)<br>
    <br>
    ----------------------------------------------- mysql.lua
    -----------------------------------------------<br>
    <br>
    require 'luasql.mysql'<br>
    <br>
    DB = {}<br>
    DB.__index = DB<br>
    <br>
    function DB.create()<br>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; local db = {}<br>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; setmetatable(db,DB)<br>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; db.env = assert( luasql.mysql() )<br>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; db.con = assert(
    db.env:connect('DB','USER','PASSWORD','HOST') )<br>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return db<br>
    end<br>
    <br>
    function DB:query(query)<br>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; local q,r = self.con:execute(query)<br>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if q == nil then<br>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return nil<br>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; else<br>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return q<br>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; end<br>
    end<br>
    <br>
    function DB:fetch(cur)<br>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (cur ~= nil) then<br>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return cur:fetch({},"a");<br>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; else<br>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return nil;<br>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; end<br>
    end<br>
    <br>
    function DB:close()<br>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; self.con:close()<br>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; self.env:close()<br>
    end<br>
    <br>
    ----------------------------------------------- /mysql.lua
    -----------------------------------------------<br>
    <br>
    Exemple usage ( in a global do ... end block to ensure no data is
    global and everything is destroyed ): <br>
    <br>
    local db = DB.create();<br>
    local r = db:query("SELECT * FROM test");<br>
    local f = db:fetch(r);<br>
    db:close();<br>
    <br>
    <br>
    Le 14/03/2011 15:28, Pete Kelly a &eacute;crit&nbsp;:
    <blockquote
      cite="mid:AANLkTimLNa73o5Y_h6KUpTptNyX6Q-6bpBOQBjLtsnS6@mail.gmail.com"
      type="cite"><br>
      <br>
      <div class="gmail_quote">On 14 March 2011 13:16, Steven Ayre <span
          dir="ltr">&lt;<a moz-do-not-send="true"
            href="mailto:steveayre@gmail.com">steveayre@gmail.com</a>&gt;</span>
        wrote:<br>
        <blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt
          0.8ex; border-left: 1px solid rgb(204, 204, 204);
          padding-left: 1ex;">
          If you use mod_lcr, we were getting a memory leak in that a
          few weeks ago which is fixed in the latest git.</blockquote>
        <div><br>
        </div>
        <div>No we are not. I am going to try strengthening up the code
          which closes the DB connections. If that fails then I will
          compile and try the ODBC driver.</div>
        <div>&nbsp;</div>
        <blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt
          0.8ex; border-left: 1px solid rgb(204, 204, 204);
          padding-left: 1ex;">
          <div>
            <div><br>
            </div>
            <div>-Steve</div>
            <div><br>
              <br>
              <div class="gmail_quote">
                <div>
                  <div class="h5">
                    On 14 March 2011 09:30, Pete Kelly <span dir="ltr">&lt;<a
                        moz-do-not-send="true"
                        href="mailto:pkelly@gmail.com" target="_blank">pkelly@gmail.com</a>&gt;</span>
                    wrote:<br>
                  </div>
                </div>
                <blockquote class="gmail_quote" style="margin: 0pt 0pt
                  0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204);
                  padding-left: 1ex;">
                  <div>
                    <div class="h5">Hi
                      <div><br>
                        We are using Freeswitch (from git sources) in a
                        production environment to handle an IVR system
                        using a simple set of dialplans and lua scripts.
                        OpenSIPS 1.6 and mysql are also installed and
                        running as part of the same IVR application.</div>
                      <div><br>
                      </div>
                      <div>However over time (approx 1 week) the memory
                        usage of Freeswitch increases, eventually
                        creeping into swap space forcing us to restart
                        Freeswitch. The IVR handles approx 40 concurrent
                        calls constantly, and we have instances of the
                        IVR running on a 32bit Etch and 64bit Lenny
                        boxes - both exhibit the same issue.</div>
                      <div><br>
                      </div>
                      <div>We have also tried the Sangoma freeswitch
                        branch in case that contained any fixes, however
                        we see the same issues.</div>
                      <div><br>
                      </div>
                      <div>Can anybody advise if this is a known issue
                        with Freeswitch? Is it a memory leak or is it
                        possible to limit the amount of memory
                        Freeswitch will use, forcing it to garbage
                        collect when it reaches the limit?&nbsp;</div>
                      <div><br>
                      </div>
                      <div>Any advice on where to look/debug next would
                        be appreciated.</div>
                      <div><br>
                      </div>
                      <div>Thanks</div>
                      <div><br>
                      </div>
                      <font color="#888888">
                        <div>Pete</div>
                        <div><br>
                        </div>
                        <div><br>
                        </div>
                      </font><br>
                    </div>
                  </div>
                  <div class="im">_______________________________________________<br>
                    FreeSWITCH-users mailing list<br>
                    <a moz-do-not-send="true"
                      href="mailto:FreeSWITCH-users@lists.freeswitch.org"
                      target="_blank">FreeSWITCH-users@lists.freeswitch.org</a><br>
                    <a moz-do-not-send="true"
                      href="http://lists.freeswitch.org/mailman/listinfo/freeswitch-users"
                      target="_blank">http://lists.freeswitch.org/mailman/listinfo/freeswitch-users</a><br>
                    UNSUBSCRIBE:<a moz-do-not-send="true"
                      href="http://lists.freeswitch.org/mailman/options/freeswitch-users"
                      target="_blank">http://lists.freeswitch.org/mailman/options/freeswitch-users</a><br>
                    <a moz-do-not-send="true"
                      href="http://www.freeswitch.org" target="_blank">http://www.freeswitch.org</a><br>
                    <br>
                  </div>
                </blockquote>
              </div>
              <br>
            </div>
          </div>
          <br>
          _______________________________________________<br>
          FreeSWITCH-users mailing list<br>
          <a moz-do-not-send="true"
            href="mailto:FreeSWITCH-users@lists.freeswitch.org">FreeSWITCH-users@lists.freeswitch.org</a><br>
          <a moz-do-not-send="true"
            href="http://lists.freeswitch.org/mailman/listinfo/freeswitch-users"
            target="_blank">http://lists.freeswitch.org/mailman/listinfo/freeswitch-users</a><br>
          UNSUBSCRIBE:<a moz-do-not-send="true"
            href="http://lists.freeswitch.org/mailman/options/freeswitch-users"
            target="_blank">http://lists.freeswitch.org/mailman/options/freeswitch-users</a><br>
          <a moz-do-not-send="true" href="http://www.freeswitch.org"
            target="_blank">http://www.freeswitch.org</a><br>
          <br>
        </blockquote>
      </div>
      <br>
      <pre wrap="">
<fieldset class="mimeAttachmentHeader"></fieldset>
_______________________________________________
FreeSWITCH-users mailing list
<a class="moz-txt-link-abbreviated" href="mailto:FreeSWITCH-users@lists.freeswitch.org">FreeSWITCH-users@lists.freeswitch.org</a>
<a class="moz-txt-link-freetext" href="http://lists.freeswitch.org/mailman/listinfo/freeswitch-users">http://lists.freeswitch.org/mailman/listinfo/freeswitch-users</a>
UNSUBSCRIBE:<a class="moz-txt-link-freetext" href="http://lists.freeswitch.org/mailman/options/freeswitch-users">http://lists.freeswitch.org/mailman/options/freeswitch-users</a>
<a class="moz-txt-link-freetext" href="http://www.freeswitch.org">http://www.freeswitch.org</a>
</pre>
    </blockquote>
  </body>
</html>