odbc, dbi modules memory leak???

Victor Muslin victor at prodigy.net
Thu May 24 19:52:59 CEST 2001


The program below leaks memory:

The offender seems to be the statement:

	cur = dbconn.cursor()

If this statement is moved outside the loop so that the same cursor is
re-used, memory leak stops. Why is the cursor not garbage collected
properly?? Is there some trick I need to know? Help would be greatly
appreciated.

I know that explicit deletes should not be necessary, just tried them
in desperation :-(

I am using ActiveState Python 2.1 build 210 on Windows 2000. I
observed the same behavior with BeOpen Python 2.0.

TIA

--------------------------------------------------------

import dbi,odbc

sql = "SELECT application_instance, parameter_name,"\
      " parameter_value"\
      " FROM config_parameters"\
      " WHERE ((application_type = '%s' AND "\
      " (application_instance IS NULL OR"\
      " application_instance = '%s'))"\
      " AND (parameter_name LIKE '%s'))" % ('ADSERVER', 'ADSERVER_1',
'%')


cs = 'dbsource_acf/vmuslin/dclk123'


dbconn = odbc.odbc(cs)
for i in range(2000):
    cur = dbconn.cursor()	# <--- offending statement
    cur.execute(sql)
    resultset = cur.fetchall()
    del(cur)
    del(resultset)




More information about the Python-list mailing list