Fix a bunch of memory leaks in KisPopupPalette (+cleanup)
ClosedPublic

Authored by gladhorn on Nov 4 2016, 7:27 PM.

Details

Summary
  • Reduce duplicate initializations (initializer lists are always

preferable).

  • Initialize a few variables that were not initialized before

(m_hovered_Preset, ...)

Allocate QRect on the stack, heap allocations are expensive and were
mostly leaked.

Diff Detail

Repository
R37 Krita
Lint
Automatic diff as part of commit; lint not applicable.
Unit
Automatic diff as part of commit; unit tests not applicable.
gladhorn updated this revision to Diff 7909.Nov 4 2016, 7:27 PM
gladhorn retitled this revision from to Fix a bunch of memory leaks in KisPopupPalette (+cleanup).
gladhorn updated this object.
gladhorn edited the test plan for this revision. (Show Details)
gladhorn added reviewers: Krita, scottpetrovic.
scottpetrovic edited edge metadata.Nov 4 2016, 7:40 PM

this seems fine. One question about when to put something on the stack or on the heap...

KisHighlightedToolButton* mirrorMode;
KisHighlightedToolButton* canvasOnlyButton;
QPushButton* zoomToOneHundredPercentButton;
QSlider* zoomCanvasSlider;

These variables are still using pointers. Why not put these on the stack too?

rempt added a subscriber: rempt.Nov 5 2016, 9:37 AM

this seems fine. One question about when to put something on the stack or on the heap...

KisHighlightedToolButton* mirrorMode;
KisHighlightedToolButton* canvasOnlyButton;
QPushButton* zoomToOneHundredPercentButton;
QSlider* zoomCanvasSlider;

These variables are still using pointers. Why not put these on the stack too?

Those are widgets, which are part of the widget hierarchy. Those need to be created on the heap, because the widgets that own them will delete them. If you would put them on the stack, they would be double-deleted when they go out of scope.

this seems fine. One question about when to put something on the stack or on the heap...

KisHighlightedToolButton* mirrorMode;
KisHighlightedToolButton* canvasOnlyButton;
QPushButton* zoomToOneHundredPercentButton;
QSlider* zoomCanvasSlider;

These variables are still using pointers. Why not put these on the stack too?

The way it works here is that they inherit QObject which is allowing an alternative way of memory management. QObjects (QWidget and friends) can have a "parent" to build a hierarchy. When deleting the parent, it deletes all it's children. That's how it's done for most of the UI things.

This revision was automatically updated to reflect the committed changes.

thanks for the advice. I knew about QWidgets having some type of inheritance that makes them memory management, but didn't realize all "Q" classes do not follow that same pattern (QRect, etc)