import QtQuick // Holds one count on a service's demand counter while `active`, released when // inactive or destroyed. Services run their samplers and processes only while // counted, so idle views cost nothing. QtObject { id: root required property var service property string counter: "consumers" property bool active: true property bool held: false function sync() { const next = active && !!service; if (next === held) return; service[counter] += next ? 1 : -1; held = next; } onActiveChanged: sync() Component.onCompleted: sync() Component.onDestruction: if (held) service[counter]-- }