• 4930阅读
  • 0回复

为什么我的窗口关闭后也不释放系统资源! [复制链接]

上一主题 下一主题
离线buben
 

只看楼主 倒序阅读 楼主  发表于: 2006-05-24
我也遇到与seraphliu类似的问题!程序是用python写的,用Qt做界面,做了一个显示数据库表的表格窗口。但是当关闭这个表格窗口时,内存并不释放。据说python有自己的内存回收功能,不用程序员操心。但如果python不释放,该怎么办?下面是我的部分python程序:
...
self.connect(self.applyBtn,SIGNAL("clicked()"),self.showAll)
...
def showAll(self):
    if self.filename:
        self.a=Form1(self,value=self.filename)
        self.a.show()

class Form1(QDialog):        
  def __init__(self, parent=None, value=None):
    QDialog.__init__(self, parent, "View Whole Table")
    self.value=value
    self.table1 = QTable(self,"table1")
    self.table1.setGeometry(QRect(0,0,800,560))
    self.table1.setMinimumWidth(200)
     
    mydb=MySQLdb.Connect(host="localhost", db="test",user="root",passwd="root")
    mycursor=mydb.cursor()
    stmt="select max(index) from %s"% str(self.value)
    mycursor.execute(stmt)
    result = mycursor.fetchone()
    numEx=result[0]
    self.table1.setNumRows(numEx)
   
    stmt="describe %s"% str(self.value)
    mycursor.execute(stmt)
    result = mycursor.fetchall()
    numCo=len(result);
    self.table1.setNumCols(numCo)
         
   
    self.languageChange()
    hheader=self.table1.horizontalHeader()
   
    stmt="select * from %svartype"% str(self.value)
    mycursor.execute(stmt)
    result = mycursor.fetchall()
    i=0
    jj=0
    for record in result:
        if jj==0:
          for nam in record:
            clonam=nam
            hheader.setLabel(i, unicode(clonam,'MBCS'))
            i +=1
          jj +=1
   
   
    j=0
    while(j<numCo):  
        stmt="select var%s from %s" %(j,self.value)
        mycursor.execute(stmt)
        result = mycursor.fetchall()
        i=0
        for record in result:
          x=record[0]
          self.table1.setText(i, j, unicode(str(x),'MBCS'))
          i +=1
        j +=1
       
    mycursor.close()
    mydb.close()  
   
  def languageChange(self):
    self.setCaption(self.__tr("Form1"))
 
  def __tr(self,s,c = None):
    return qApp.translate("Form1",s,c)
快速回复
限100 字节
 
上一个 下一个