2011-07-12 42 views
0

我發現使用selectby方法和sqlobject存在泄漏內存。sqlobject:使用selectby方法泄漏內存

例如,當我執行此代碼:

connection = connectionForURI('postgresql://test:[email protected]/test_sql_object') 
tran = connection.transaction() 
sqlhub.threadConnection = tran 


class Person(SQLObject): 

    firstName = StringCol() 
    middleInitial = StringCol(length=1, default=None) 
    lastName = StringCol() 


for iteration in range(20): 
    start = datetime.now() 
    for key in range(1000): 
     person = Person.selectBy(firstName='name%s%s' % (iteration,key)) 
     if person: 
      select = person[0] 
    end = datetime.now() 
    print "TIME ",iteration,':' , end - start 

,其結果是

TIME 0 : 0:00:03.328198 
TIME 1 : 0:00:03.382905 
TIME 2 : 0:00:03.690991 
TIME 3 : 0:00:04.436301 
TIME 4 : 0:00:05.021656 
TIME 5 : 0:00:05.393993 
TIME 6 : 0:00:05.791572 
TIME 7 : 0:00:06.151833 
TIME 8 : 0:00:06.517327 
TIME 9 : 0:00:06.779239 
TIME 10 : 0:00:06.961454 
TIME 11 : 0:00:06.872361 
TIME 12 : 0:00:07.114973 
TIME 13 : 0:00:07.473208 
TIME 14 : 0:00:07.737618 
TIME 15 : 0:00:07.951056 
TIME 16 : 0:00:08.199360 
TIME 17 : 0:00:08.600283 
TIME 18 : 0:00:08.802639 
TIME 19 : 0:00:09.131514s 

我測試使用connection.clear(),過期等,但我得到了相同的結果。 例如,如果我改變Person類

class Person(SQLObject): 
    class sqlmeta: 
     cacheValues = False 

    firstName = StringCol() 
    middleInitial = StringCol(length=1, default=None) 
    lastName = StringCol() 

結果是

TIME 0 : 0:00:03.298583 
TIME 1 : 0:00:03.465153 
TIME 2 : 0:00:03.955067 
TIME 3 : 0:00:04.594931 
TIME 4 : 0:00:05.062099 
TIME 5 : 0:00:05.172968 
TIME 6 : 0:00:06.011087 
TIME 7 : 0:00:06.106087 
TIME 8 : 0:00:06.475573 
TIME 9 : 0:00:06.836605 
TIME 10 : 0:00:06.963226 
TIME 11 : 0:00:06.889263 
TIME 12 : 0:00:07.219188 
TIME 13 : 0:00:07.417601 
TIME 14 : 0:00:07.737096 
TIME 15 : 0:00:08.128259 
TIME 16 : 0:00:08.217653 
TIME 17 : 0:00:08.612468 
TIME 18 : 0:00:08.800511 
TIME 19 : 0:00:08.979550 

感謝。

回答