Fix two memory "leaks"
-
don't make duplicate connections to
ThemePrivate::onAppExitCleanup
Plasma::Theme::Theme(…)
andPlasma::Theme::setThemeName(…)
were unconditionally connecting theQCoreApplication::aboutToQuit
signal to theThemePrivate::onAppExitCleanup
slot, even though theThemePrivate
instances are cached and shared across multipleTheme
instances. In long-running applications that make heavy use of theSvg
class (such asplasmashell
), a singleThemePrivate
instance can be reused by huge numbers ofTheme
instances. If the reference count of thatThemePrivate
instance never reaches zero, then the connections just keep piling up, contributing to excessive memory usage. This commit moves the relevantconnect(…)
call so that it only happens in the case that a newThemePrivate
instance is constructed. Thus, there will only ever be one connection fromQCoreApplication::aboutToQuit
toThemePrivate::onAppExitCleanup
per instance ofThemePrivate
. -
avoid holding onto old
Svg
object when changing source of anIconItem
A long-lived
IconItem
instance can have its source changed many times over its lifetime. BecauseSvgSource
parents its internalPlasma::Svg
instance to theIconItem
instance, this means that suchPlasma::Svg
instance was not being destroyed when its responsibleSvgSource
instance is destroyed and indeed would not be destroyed until theIconItem
instance is eventually destroyed, which could be arbitrarily much later. This commit adds an explicit call in theSvgSource
destructor to delete thePlasma::Svg
instance so it does not hang around in memory until theIconItem
instance is destroyed. This fixes one of the major memory "leaks" inplasmashell
.