Solved :
Apparently the problem wasn't in deallocating images, it was in the command I used to get the image location(the database->cell method) I didn't consider this because the dataCache also used the method. But here is what was going on, the "thumbnail" + thumbnailSize column was set as type "Icon" which meant the database would link to the icon database and from that the current icon theme database. When it linked it would call the index->set method to update the index to the correct location:
//Constructer
: AbstractIndex(location, parent)
{
set(location);
}
//Destructer
Index::~Index()
{/* Do nothing*/}
/*
*sets the index's location
*/
void Index
::set(const QString &location
) {
index = new Storage(location + "/" + "index", this);
indexAll = new Storage(location + "/" + "index.all", this);
indexEntrys = new Storage(location + "/" + "index.entrys", this);
indexStartsWith = new Storage(location + "/" + "index.startswith", this);
}
//Constructer
Index::Index(const QString &location, QObject *parent)
: AbstractIndex(location, parent)
{
set(location);
}
//Destructer
Index::~Index()
{/* Do nothing*/}
/*
*sets the index's location
*/
void Index::set(const QString &location)
{
index = new Storage(location + "/" + "index", this);
indexAll = new Storage(location + "/" + "index.all", this);
indexEntrys = new Storage(location + "/" + "index.entrys", this);
indexStartsWith = new Storage(location + "/" + "index.startswith", this);
}
To copy to clipboard, switch view to plain text mode
so every time the set command was called all these storage objects would just be recreated without the old ones being deleted! I don't know how I made such a big mistake .
Thanks everyone for your help .
~Timothy
Hi,
I have a method that fills a QList<QPixmap*> after attempting to delete its previous content:
thumbnails.clear();
for(int row = 0; row < currentRows.size(); row++)
{
QPixmap image
(database
->cell
(currentRows.
at(row
),
"thumbnail" + thumbnailSize
));
thumbnails += image;
}
QPixmapCache::clear();
thumbnails.clear();
for(int row = 0; row < currentRows.size(); row++)
{
QPixmap image(database->cell(currentRows.at(row), "thumbnail" + thumbnailSize));
thumbnails += image;
}
To copy to clipboard, switch view to plain text mode
However when I look at the application on KSystemGaurd its ram usage raises by 1 meg everytime that method is called (I can get my application to use 2Gb of ram just by calling that method enough times) If I remove the following lines:
QPixmap *image
= new QPixmap(database
->cell
(currentRows.
at(row
),
"thumbnail" + thumbnailSize
));
thumbnails += image;
QPixmap *image = new QPixmap(database->cell(currentRows.at(row), "thumbnail" + thumbnailSize));
thumbnails += image;
To copy to clipboard, switch view to plain text mode
the memory leak dissappears, what am I doing wrong?
Edit:
here is the entire method:
void DatabaseModel::display()
{
if(currentRows.size() > 0){
currentRows.clear();
endRemoveRows();
}
qint64 currentOffset = 0;
currentRows = database->rows(positionCache.last(), maxShown, currentOffset);
qDeleteAll(dataCache);
dataCache.clear();
thumbnails.clear();
for(int row = 0; row < currentRows.size(); row++)
{
for(int col = 0; col < cols.size(); col++){
rowData->append(database->cell(currentRows.at(row), cols.at(col)));
}
dataCache += rowData;
QPixmap image
(database
->cell
(currentRows.
at(row
),
"thumbnail" + thumbnailSize
));
thumbnails += image;
}
positionCache += currentOffset;
endInsertRows();
}
void DatabaseModel::display()
{
if(currentRows.size() > 0){
beginRemoveRows(QModelIndex(), 0, currentRows.size());
currentRows.clear();
endRemoveRows();
}
beginInsertRows(QModelIndex(), 0, currentRows.size());
qint64 currentOffset = 0;
currentRows = database->rows(positionCache.last(), maxShown, currentOffset);
qDeleteAll(dataCache);
dataCache.clear();
QPixmapCache::clear();
thumbnails.clear();
for(int row = 0; row < currentRows.size(); row++)
{
QStringList *rowData = new QStringList;
for(int col = 0; col < cols.size(); col++){
rowData->append(database->cell(currentRows.at(row), cols.at(col)));
}
dataCache += rowData;
QPixmap image(database->cell(currentRows.at(row), "thumbnail" + thumbnailSize));
thumbnails += image;
}
positionCache += currentOffset;
endInsertRows();
}
To copy to clipboard, switch view to plain text mode
I am using the latest Qt update for kubuntu: 4.3.0-4.
Thanks in advance ,
~Timothy
Bookmarks