Results 1 to 9 of 9

Thread: Qt Mem Leak/growth with queued connections across threads?

  1. #1
    Join Date
    Apr 2007
    Location
    United States
    Posts
    17
    Thanks
    2
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Qt Mem Leak/growth with queued connections across threads?

    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

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Qt Mem Leak/growth with queued connections across threads?

    Do all treads connected to that signal have running event loop?

  3. #3
    Join Date
    Apr 2007
    Location
    United States
    Posts
    17
    Thanks
    2
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Qt Mem Leak/growth with queued connections across threads?

    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?

  4. #4
    Join Date
    Apr 2007
    Location
    United States
    Posts
    17
    Thanks
    2
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Qt Mem Leak/growth with queued connections across threads?

    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.

  5. #5
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Qt Mem Leak/growth with queued connections across threads?

    Quote Originally Posted by chuckshaw View Post
    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()).

    Quote Originally Posted by chuckshaw View Post
    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?

  6. #6
    Join Date
    Apr 2007
    Location
    United States
    Posts
    17
    Thanks
    2
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Qt Mem Leak/growth with queued connections across threads?

    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.

  7. #7
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Qt Mem Leak/growth with queued connections across threads?

    Quote Originally Posted by chuckshaw View Post
    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.

    Quote Originally Posted by chuckshaw View Post
    The error that i get isn't an error per say.
    I meant the error that appears when you try to upload the attachment.

  8. The following user says thank you to jacek for this useful post:

    chuckshaw (16th August 2008)

  9. #8
    Join Date
    Apr 2007
    Location
    United States
    Posts
    17
    Thanks
    2
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Qt Mem Leak/growth with queued connections across threads?

    The error I get says something to the effect of "can't get security token". That occurs after I hit the "upload" button.

  10. #9
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Qt Mem Leak/growth with queued connections across threads?

    Quote Originally Posted by chuckshaw View Post
    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?

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.