Skip to content

Commit dbf70c6

Browse files
committedOct 19, 2014
[composer] Fix a memory leak when destroying compositions
1 parent 9d0b83a commit dbf70c6

File tree

1 file changed

+9
-11
lines changed

1 file changed

+9
-11
lines changed
 

‎src/core/composer/qgscomposition.cpp

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -187,16 +187,16 @@ QgsComposition::~QgsComposition()
187187
removePaperItems();
188188
deleteAndRemoveMultiFrames();
189189

190-
// clear pointers to QgsDataDefined objects
191-
//TODO - should be qDeleteAll? Check original label code too for same leak.
192-
mDataDefinedProperties.clear();
193-
194190
// make sure that all composer items are removed before
195191
// this class is deconstructed - to avoid segfaults
196192
// when composer items access in destructor composition that isn't valid anymore
197193
QList<QGraphicsItem*> itemList = items();
198194
qDeleteAll( itemList );
199195

196+
// clear pointers to QgsDataDefined objects
197+
qDeleteAll( mDataDefinedProperties );
198+
mDataDefinedProperties.clear();
199+
200200
//order is important here - we need to delete model last so that all items have already
201201
//been deleted. Deleting the undo stack will also delete any items which have been
202202
//removed from the scene, so this needs to be done before deleting the model
@@ -925,13 +925,14 @@ bool QgsComposition::loadFromTemplate( const QDomDocument& doc, QMap<QString, QS
925925
{
926926
deleteAndRemoveMultiFrames();
927927

928-
//delete all items and emit itemRemoved signal
928+
//delete all non paper items and emit itemRemoved signal
929929
QList<QGraphicsItem *> itemList = items();
930930
QList<QGraphicsItem *>::iterator itemIter = itemList.begin();
931931
for ( ; itemIter != itemList.end(); ++itemIter )
932932
{
933933
QgsComposerItem* cItem = dynamic_cast<QgsComposerItem*>( *itemIter );
934-
if ( cItem )
934+
QgsPaperItem* pItem = dynamic_cast<QgsPaperItem*>( *itemIter );
935+
if ( cItem && !pItem )
935936
{
936937
removeItem( cItem );
937938
emit itemRemoved( cItem );
@@ -940,7 +941,7 @@ bool QgsComposition::loadFromTemplate( const QDomDocument& doc, QMap<QString, QS
940941
}
941942
mItemsModel->clear();
942943

943-
mPages.clear();
944+
removePaperItems();
944945
mUndoStack->clear();
945946
}
946947

@@ -2550,10 +2551,7 @@ void QgsComposition::addPaperItem()
25502551

25512552
void QgsComposition::removePaperItems()
25522553
{
2553-
for ( int i = 0; i < mPages.size(); ++i )
2554-
{
2555-
delete mPages.at( i );
2556-
}
2554+
qDeleteAll( mPages );
25572555
mPages.clear();
25582556
QgsExpression::setSpecialColumn( "$numpages", QVariant(( int )0 ) );
25592557
}

0 commit comments

Comments
 (0)
Please sign in to comment.