a note on using Plasma::DataEngine::serviceForSource

Aaron J. Seigo aseigo at kde.org
Tue Jun 1 23:49:54 CEST 2010


hi all ..

i've noticed a very common mistake in the plasmoids and spent some time fixing 
it everywhere i could find it today, so i figured i should pop this to the 
list :)

whenever DataEngine::serviceForSource is called a NEW Plasma::Service is 
created and returned. the service is, by default, parented to the DataEngine, 
so when the DataEngine goes away the service will as well. however, that is 
just a safety measure.

when the service is no longer useful to the user of it, it really ought to be 
cleaned up. there are two ways to do this:

if the service it going to live as long as the object (e.g. the 
Plasma::Applet) that is using that service, then simply do:

     service->setParent(this); 

(replace "this" with whatever object's lifetime it should match, though 
usually it's the this object)

if the service is going to be used for just one operations call, then 
something like this:

Plasma::Service *service = engine->serviceForSource("notification");
KConfigGroup op = service->operationDescription("someOp");
ServiceJob *job = service->startOperationCall(op);
connect(job, SIGNAL(finished(KJob*)), service, SLOT(deleteLater()));


this actually explains a lot of the "plasma's memory footprint grows slowly 
over time" reports. :) let's try to keep an eye on this in the future.

-- 
Aaron J. Seigo
humru othro a kohnu se
GPG Fingerprint: 8B8B 2209 0C6F 7C47 B1EA  EE75 D6B7 2EB1 A7F1 DB43

KDE core developer sponsored by Qt Development Frameworks
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 198 bytes
Desc: This is a digitally signed message part.
Url : http://mail.kde.org/pipermail/plasma-devel/attachments/20100601/2f211c20/attachment.sig 


More information about the Plasma-devel mailing list