PDA

View Full Version : Qt Mem Leak/growth with queued connections across threads?



chuckshaw
15th August 2008, 21:44
I have set up connections that are of type auto connection. The signals are sent across threads so they are queued connections in those instances. We are seeing serious mem growth per message emitted even with the slot doing absolutely nothing other than saying "i got called". So we know that the correct number of slots are getting called. Qt should clean up any thing it had made a copy of at this point.

Has anyone else seen this pattern? Is there anyway to force Qt to clean up after itself?

You can see this yourself if you simply make a quick connection of type queued. And send a specified number of signals to a generic slot. You can watch mem growth as each is sent. If you use a type of direct connection then the mem does not grow. This pattern will continue till you stop sending messages and the memory will never be reclaimed.

Thanks,

Chuck

jacek
15th August 2008, 22:55
Do all treads connected to that signal have running event loop?

chuckshaw
15th August 2008, 23:37
I do not explicitly call exec() in the run method. However according to the docs: " By default, run() starts the event loop by calling exec()" So I assume that all threads would have an event loop. Is that a bad assumption and should I explicitly call "exec()" in each run() function?

chuckshaw
15th August 2008, 23:56
Also I wanted to add that we setup a simple test case (which qtcentre errors out upon upload or i would have included it) where we have a single object. In that object we setup the connect() call using the optional type specifier for queued connection. Then sending signals in a while loop to a slot inside the object produces the same behavior.

jacek
16th August 2008, 00:16
Is that a bad assumption and should I explicitly call "exec()" in each run() function?
Such behavior was introduced in 4.4.0, so if you use Qt 4.4.0 or newer you don't have to invoke it explicitly (of course only if you leave default implementation of run()).


Also I wanted to add that we setup a simple test case (which qtcentre errors out upon upload or i would have included it)
What error do you get exactly?

chuckshaw
16th August 2008, 00:37
Well for some of my run() methods, they consist of while loops that are an event loop in themselves. As run() never exits until the thread is killed. In this case does exec() not get invoked?

The error that i get isn't an error per say. For example, using a while(true) loop and emitting a signal that was connected to a slot with the queued type, will allocate memory until the system runs out and the app crashes. This is what my simple test case does that I mentioned previously. Simply stated, the mem that is used in between the emit signal and the Slot being called is never free'ed.

jacek
16th August 2008, 01:24
Well for some of my run() methods, they consist of while loops that are an event loop in themselves.
If you have your own run(), then the original is never called. If you won't process events in the thread, all queued signals delivered to it will be queued forever.


The error that i get isn't an error per say.
I meant the error that appears when you try to upload the attachment.

chuckshaw
16th August 2008, 01:28
The error I get says something to the effect of "can't get security token". That occurs after I hit the "upload" button.

jacek
16th August 2008, 16:43
The error I get says something to the effect of "can't get security token". That occurs after I hit the "upload" button.
What is the extension of the file you wanted to upload?