Alexis Marrero wrote:
> Jim,
> This are my results for the memory leak search in apache.table().
> The table object creates a memory pool by using apr_pool_create_ex() and
> destroys the pool using apr_pool_destroy(). I added a line in
> MpTable_New() before "return (PyObject*)t" to destroy the pool and ran
> 1M iterations and I notice that there was no memory leak.  Therefore the
> apache functions seems to be working fine.

That's weird though, because I stuffed some printf's into table_dealloc,
and apr_pool_destroy(self->pool) is getting called.

> I couldn't fix the problem but here is a work around. In
> mod_python/ instead of using apache.make_table() use a regular
> Python dictionary.  So the line that looks like:
> headers = apache.make_table()
> now looks like:
> headers = {}
> The apache table is basically used a Python dictionary. The only
> functionality that is lost is that apache tables are case insensitive,
> and that can be easily fixed by creating a class in Python that inherits
> from dict type and override the __getitem__ and  __setitem__ methods.

I had considered the idea of using a standard python dict, but there is
one other difference that may be important. Apache tables (and therefore
the mp_table wrapper) can have duplicate keys. I'd rather we didn't
create a whole new class for use in FieldStorage.

> For the moment I'm going to keep this changes until
> release a patch.  I spent quite sometime trying to investigate and solve
> the memory leak problem but the best I was able to do was to work around
> it.

This workaround may be fine for your application where you control what
is being POSTed, but I'm not so sure about it as a general solution as
the change may break other apps.

> BTW,  apache.table, apache.make_table or _apache.table is only being
> used in mod_python/

True, but the mp_table wrapper is used extensively within mod_python,
but these table instances are created using MpTable_FromTable() rather
than MpTable_New(). I'd like to understand why we are getting leak with
MpTable_New(), as it may point to some other bug in mp_table.

BTW, thanks for the time you've spent digging into these leaks.


> /amn
> On Aug 13, 2006, at 12:01 PM, Jim Gallacher (JIRA) wrote:
>> Memory leak apache.table()
>> --------------------------
>>                  Key: MODPYTHON-184
>>                  URL:
>>              Project: mod_python
>>           Issue Type: Bug
>>           Components: core
>>     Affects Versions: 3.2.10, 3.3
>>             Reporter: Jim Gallacher
>>          Assigned To: Jim Gallacher
>> There is a memory leak in apache.table().
>> from mod_python import apache
>> def handler(req):
>>     req.content_type = 'text/plain'
>>     t = apache.make_table()
>>     req.write('ok table:')
>>     return apache.OK
>> Using mpm-worker with StartServers 2, and 20000 requests results in
>> memory consumption going from 1.2% to 9.3% per process. (ie approx 8k
>> per request)
>> --This message is automatically generated by JIRA.
>> -
>> If you think it was sent incorrectly contact one of the
>> administrators:
>> -
>> For more information on JIRA, see:

Reply via email to