[SOLVED] my code make my memory increasing



  • How to correct my code?

       void diaOpenFileByListView::BindLV(){
       int curRow=-1;
       if(model!=0 && ui->lvwFile->currentIndex().row()>0){
            curRow= ui->lvwFile->currentIndex().row();
        }
        init_styleditemdelegate_cell *listdelegate;
        model = new QStandardItemModel(this);
        ui->lvwFile->setModel(model);
        listdelegate = new init_styleditemdelegate_cell();
        ui->lvwFile->setItemDelegate(listdelegate);
        QDir dir=QDir::rootPath();
        QString myPath;
        myPath=gData->strFileFolder;
        dir.cd(myPath);
        ui->lblPath->setText(dir.absolutePath());
        dir.setNameFilters(QStringList()<<"*.qqq");
        QStringList fileList = dir.entryList();
        QStandardItem *item ;//= new QStandardItem();
        for (int i=0; i<fileList.count(); i++)
        {
            item = new QStandardItem();
            QString tmpFilePaht=dir.absolutePath()+"/"+fileList[i];
            QIcon icon=GetListIcon(tmpFilePaht);
            item->setData(icon,init_styleditemdelegate_cell::IconRole);
            item->setData(tmpFilePaht,init_styleditemdelegate_cell::headerTextRole);
            item->setData(fileList[i],init_styleditemdelegate_cell::subHeaderTextrole);
            item->setEditable(false);
            model->appendRow(item);
        }
       if(model->rowCount()>0){
            if(curRow>-1){
                ui->lvwFile->setCurrentIndex(model->indexFromItem(model->item(curRow,0)));
            }else{
                ui->lvwFile->setCurrentIndex(model->indexFromItem(model->item(0,0)));
            }
        }
        ShowIni();
        }
    


  • This post is deleted!


  • The only leak I can find is caused by ui->lvwFile->setModel(model). setModel(model) does not free the old model, instead you need to delete it manually. Your coding style could use some fine tuning init_styleditemdelegate_cell is absolutely horrible class name, and you could add a few newlines here and there to group logical pieces together.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.