Memory leak in ibm_db.fetch_assoc()

26 views
Skip to first unread message

paul

unread,
Aug 7, 2008, 3:01:16 AM8/7/08
to ibm_db
Hi,

There seems to be a serious memory leak in the the
ibm_db.fetch_assoc() function! :(

I'm doing the following:

sql = "SELECT filename, data FROM files WHERE id = ... ";
stmt = ibm_db.exec_immediate(conn,sql);
row = ibm_db.fetch_assoc(stmt);
row.clear(); # Just to be sure.
ibm_db.free_result(stmt);

Each time that code block runs, more memory is allocated, and not
released. Since the data column, in this case, is typically around
30kB, the memory usage grows quite quickly - easily reaching 700MB+ in
an hour or so. If I comment out the fetch_assoc() call (and
row.clear()) then the memory usage remains solid at around 16MB.

I'm not very familiar with Python (primarily a C/C++ developer), so
hopefully I'm just missing something a typical Python programmer would
know... like how to free the result properly (I have tried "del row"
too, but that does not help the memory leak).

By the way, filename column is of type VARHAR(255), and data is of
type BLOB.

Any suggestions would be *highly* appreciated! Thanks :)

Paul.

abhigyan...@in.ibm.com

unread,
Aug 7, 2008, 8:52:06 AM8/7/08
to ibm_db
Hi Paul,
Please try ibm_db.free_stmt(resource stmt) and let me know
if you still face this problem.

Thanks,
Abhigyan

paul

unread,
Aug 7, 2008, 8:11:25 PM8/7/08
to ibm_db
Hi Abhigyan,

I have tried ibm_db.free_stmt(), with no success.

If I finish the code block with:

if self.adapter.free_stmt(stmt):
log(1,"free_stmt succeeded.");
else:
log(1,"free_stmt failed.");

if self.adapter.free_result(stmt):
log(1,"free_result succeeded.");
else:
log(1,"free_result failed.");

The output is:

free_stmt failed.
free_result succeeded.

And if I reverse the two free_* calls, free_stmt still fails, and
frr_result still succeeds. In both cased, the memory leak remains :(

Perhaps I should also mention that I'm using Python 2.5.2 with ibm_db
0.2.9.1. But this same leak occurs with ibm_db 0.1.0 under Python
2.4.3 too.

Thanks!! :)

Paul.

abhigyan...@in.ibm.com

unread,
Aug 12, 2008, 8:54:52 AM8/12/08
to ibm_db
Hi Paul,
I have opened an internal issue for it. Will need to dig
deeper for it. I will let you know when I am done with it.
Thanks for your patience.
Abhigyan
> > > Paul.- Hide quoted text -
>
> - Show quoted text -

paul

unread,
Aug 25, 2008, 5:43:10 PM8/25/08
to ibm_db
Hi Abhigyan,

Have you made any progress with this? :)

Thanks!

Paul.

abhigyan...@in.ibm.com

unread,
Aug 26, 2008, 8:32:26 AM8/26/08
to ibm_db
Hi Paul,
I am working on it and found the location where leak is
happening. A little more patience please. :)

Thanks,
Abhigyan
> > > - Show quoted text -- Hide quoted text -

abhigyan...@in.ibm.com

unread,
Aug 29, 2008, 7:19:34 AM8/29/08
to ibm_db
Hi Paul,
Thanks for waiting so patiently. :)
I have solved the issue. Please use the new ibm_db.c file
which doesn't have memory leak problem. The fix currently is only for
fetch_assoc() function. I will include this fix in the next release.

New ibm_db.c file and Windows egg is placed at:
http://code.google.com/p/ibm-db/issues/detail?id=13

Thanks,
Abhigyan
Reply all
Reply to author
Forward
0 new messages