Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Memory leak from calling QResource::registerResource in my main() function?
QtWS25 Last Chance

Memory leak from calling QResource::registerResource in my main() function?

Scheduled Pinned Locked Moved Solved General and Desktop
5 Posts 3 Posters 714 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    Robert Hairgrove
    wrote on last edited by
    #1

    Valgrind says so ... do I have to explicitly unregister any resources which were previously registered by calling the static function QResource::registerResource()? None of the constructors of the QResource class provide for passing a parent object, either.

    1 Reply Last reply
    0
    • Christian EhrlicherC Offline
      Christian EhrlicherC Offline
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on last edited by
      #2

      It's a 'one-time' memory-leak - i.e. it's not cleaned up on application exit but it's not that big problem since the OS cleans up the memory by it's own. It's not nice but should not hurt either.

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      R 1 Reply Last reply
      0
      • Christian EhrlicherC Christian Ehrlicher

        It's a 'one-time' memory-leak - i.e. it's not cleaned up on application exit but it's not that big problem since the OS cleans up the memory by it's own. It's not nice but should not hurt either.

        R Offline
        R Offline
        Robert Hairgrove
        wrote on last edited by
        #3

        @Christian-Ehrlicher Thanks, Christian. Nevertheless, I'd like to avoid it if possible. At least I now know that "it isn't me". I'll try avoiding the static functions and see if that makes a difference.

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          Hi,

          Yes, you have to do it yourself with QResource:: unregisterResource.

          Depending on how you are using your resources you could write a helper class like QMutexLocker

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          R 1 Reply Last reply
          2
          • SGaistS SGaist

            Hi,

            Yes, you have to do it yourself with QResource:: unregisterResource.

            Depending on how you are using your resources you could write a helper class like QMutexLocker

            R Offline
            R Offline
            Robert Hairgrove
            wrote on last edited by
            #5

            @SGaist Thanks ... I do call unregisterResource whenever I register another one, but I need to know at the end of the main() function which one is active. So the helper class sounds like a good idea.

            1 Reply Last reply
            0

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved