From f75eb2d9845aff48ec1f76f468b6065229511f96 Mon Sep 17 00:00:00 2001 From: Aleix Pol Date: Thu, 10 Jul 2014 19:53:03 +0200 Subject: [PATCH] Don't connect to signals until the class has been initialized While profiling plasmashell memory usage with Vishesh we realized that most of the usage came from loading the Background image repeatedly. We traced it back to this change, where we were connecting to wallpaperChanged before initializing it, so it would initialize it again, loading the wallpaper twice. It's not that we were leaking the object, AFAIK, but loading an image using QQuickImage already raises the memory quite a bit. This change alone reduces by 15% the memory usage of my plasmashell (with 2 screens, that makes it a bit worse, because there's 2 DesktopViews then). REVIEW: 119216 --- .../qml/plasmoid/containmentinterface.cpp | 53 ++++++++++--------- 1 file changed, 27 insertions(+), 26 deletions(-) diff --git a/src/scriptengines/qml/plasmoid/containmentinterface.cpp b/src/scriptengines/qml/plasmoid/containmentinterface.cpp index 4764430a8..6670d1393 100644 --- a/src/scriptengines/qml/plasmoid/containmentinterface.cpp +++ b/src/scriptengines/qml/plasmoid/containmentinterface.cpp @@ -61,31 +61,10 @@ ContainmentInterface::ContainmentInterface(DeclarativeAppletScript *parent, cons setAcceptedMouseButtons(Qt::AllButtons); - connect(m_containment.data(), &Plasma::Containment::appletRemoved, + connect(m_containment, &Plasma::Containment::appletRemoved, this, &ContainmentInterface::appletRemovedForward); - connect(m_containment.data(), &Plasma::Containment::appletAdded, + connect(m_containment, &Plasma::Containment::appletAdded, this, &ContainmentInterface::appletAddedForward); - connect(m_containment.data(), &Plasma::Containment::activityChanged, - this, &ContainmentInterface::activityChanged); - connect(m_containment.data(), &Plasma::Containment::activityChanged, - [ = ]() { - delete m_activityInfo; - m_activityInfo = new KActivities::Info(m_containment->activity(), this); - connect(m_activityInfo, &KActivities::Info::nameChanged, - this, &ContainmentInterface::activityNameChanged); - emit activityNameChanged(); - }); - connect(m_containment.data(), &Plasma::Containment::wallpaperChanged, - this, &ContainmentInterface::loadWallpaper); - connect(m_containment.data(), &Plasma::Containment::containmentTypeChanged, - this, &ContainmentInterface::containmentTypeChanged); - - if (m_containment->corona()) { - connect(m_containment->corona(), &Plasma::Corona::availableScreenRegionChanged, - this, &ContainmentInterface::availableScreenRegionChanged); - connect(m_containment->corona(), &Plasma::Corona::availableScreenRectChanged, - this, &ContainmentInterface::availableScreenRectChanged); - } if (!m_appletInterfaces.isEmpty()) { emit appletsChanged(); @@ -96,9 +75,9 @@ ContainmentInterface::ContainmentInterface(DeclarativeAppletScript *parent, cons if (!m_containment) { return; } - disconnect(m_containment.data(), &Plasma::Containment::appletRemoved, - this, &ContainmentInterface::appletRemovedForward); - }); + disconnect(m_containment, &Plasma::Containment::appletRemoved, + this, &ContainmentInterface::appletRemovedForward); + }); } void ContainmentInterface::init() @@ -164,6 +143,28 @@ void ContainmentInterface::init() if (!m_containment->wallpaper().isEmpty()) { loadWallpaper(); } + + connect(m_containment, &Plasma::Containment::activityChanged, + this, &ContainmentInterface::activityChanged); + connect(m_containment, &Plasma::Containment::activityChanged, + [ = ]() { + delete m_activityInfo; + m_activityInfo = new KActivities::Info(m_containment->activity(), this); + connect(m_activityInfo, &KActivities::Info::nameChanged, + this, &ContainmentInterface::activityNameChanged); + emit activityNameChanged(); + }); + connect(m_containment, &Plasma::Containment::wallpaperChanged, + this, &ContainmentInterface::loadWallpaper); + connect(m_containment, &Plasma::Containment::containmentTypeChanged, + this, &ContainmentInterface::containmentTypeChanged); + + if (m_containment->corona()) { + connect(m_containment->corona(), &Plasma::Corona::availableScreenRegionChanged, + this, &ContainmentInterface::availableScreenRegionChanged); + connect(m_containment->corona(), &Plasma::Corona::availableScreenRectChanged, + this, &ContainmentInterface::availableScreenRectChanged); + } } QList ContainmentInterface::applets()