Details
-
Bug
-
Resolution: Duplicate
-
P2: Important
-
None
-
5.3.1
-
None
-
Windows 7 with Custom built Qt 5.3.1 with OpenGL.
Description
The Private Classes QGraphicsGridLayoutPrivate and QGraphicsLinearLayoutPrivate are without any Destructor. This can lead to a high amount of Memory Leaks when dealing with dynamic widgets, removing and adding them on the fly. It should also happen when dealing with static user interfaces.
The problem is that styleInfo() creates a QGraphics*StyleInfo Object which will never be removed from the heap anymore.
To solve this these private classes need to have a destructor which deletes m_styleInfo (delete on NULL pointer is valid as well).
Suggestion:
qgraphicsgridlayout.cpp:
[...] class QGraphicsGridLayoutPrivate : public QGraphicsLayoutPrivate { public: QGraphicsGridLayoutPrivate(): m_styleInfo(0) { } ~QGraphicsGridLayoutPrivate() { delete m_styleInfo; } // <<-- this line fixes the memory problem QGraphicsLayoutStyleInfo *styleInfo() const; mutable QGraphicsLayoutStyleInfo *m_styleInfo; QGraphicsGridLayoutEngine engine; #ifdef QGRIDLAYOUTENGINE_DEBUG void dump(int indent) const; #endif }; [...] qgraphicslinearlayout.cpp: [...] class QGraphicsLinearLayoutPrivate : public QGraphicsLayoutPrivate { public: QGraphicsLinearLayoutPrivate(Qt::Orientation orientation) : orientation(orientation), m_styleInfo(0) { } ~QGraphicsLinearLayoutPrivate() { delete m_styleInfo; } // this line fixes the memory problem void removeGridItem(QGridLayoutItem *gridItem); QGraphicsLayoutStyleInfo *styleInfo() const; void fixIndex(int *index) const; int gridRow(int index) const; int gridColumn(int index) const; Qt::Orientation orientation; mutable QGraphicsLayoutStyleInfo *m_styleInfo; QGraphicsGridLayoutEngine engine; }; [...]
Attachments
Issue Links
- duplicates
-
QTBUG-10768 Memory leak in QGraphicsLinearLayoutPrivate and QGraphicsGridLayout
-
- Closed
-
- relates to
-
QTBUG-52281 QGraphicsGridLayoutPrivate::styleInfo allocates QGraphicsLayoutStyleInfo but never frees
-
- Closed
-