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. QWidget subclass leak memory-
Forum Updated to NodeBB v4.3 + New Features

QWidget subclass leak memory-

Scheduled Pinned Locked Moved General and Desktop
15 Posts 4 Posters 5.2k Views 1 Watching
  • 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.
  • B Offline
    B Offline
    blackbelt
    wrote on last edited by
    #1

    Hello Guys, I ve a subclass of QWidget:

    in the constructor I have added:
    @
    setWindowFlags(Qt::FramelessWindowHint);
    setAttribute(Qt::WA_DeleteOnClose, true);@

    all the destructor are called, in the correct order. Still I have memory leak. Does Anyone have experimented this issue?

    1 Reply Last reply
    0
    • A Offline
      A Offline
      andre
      wrote on last edited by
      #2

      How did you determine that?

      Anyway, from just these two lines of code, we can't possibly determine the cause of any memory leak.

      1 Reply Last reply
      0
      • B Offline
        B Offline
        blackbelt
        wrote on last edited by
        #3

        Windows Ce task manager. I know that it is not the best profiler tool but still It is the only tool I have available.

        thank you Andre

        1 Reply Last reply
        0
        • M Offline
          M Offline
          MichelS
          wrote on last edited by
          #4

          I don't know if you know, that Windows CE does not close your application if you close your window. The Flags you set don't influence this behavior.

          Edt: I've developed an CE application that quits on close. I'll have a look at it and post some code, if that is what you need.

          1 Reply Last reply
          0
          • B Offline
            B Offline
            blackbelt
            wrote on last edited by
            #5

            [quote author="MichelS" date="1348474193"]I don't know if you know, that Windows CE does not close your application if you close your window. The Flags you set don't influence this behavior.

            Edt: I've developed an CE application that quits on close. I'll have a look at it and post some code, if that is what you need.[/quote]

            can be this the cause of the leak ? But still all the destructors are invoked. Do you have any tool to perform memory analysis on Windows CE?

            1 Reply Last reply
            0
            • M Offline
              M Offline
              MichelS
              wrote on last edited by
              #6

              [quote author="author="blackbelt" date="1348475013"]
              can be this the cause of the leak ?
              [/quote]
              I won't call it a "leak", cause it's expected behavior to have the applications running in the background until other applications need that memory.

              [quote author="author="blackbelt" date="1348475013"]But still all the destructors are invoked.
              [/quote]
              That's kind of strange. Do you pass the point after application.exec(); in your main()?
              Is the process still running?
              [quote author="author="blackbelt" date="1348475013"]
              Do you have any tool to perform memory analysis on Windows CE?[/quote]
              Maybe. You can try "Visual Leak Detector":http://vld.codeplex.com/ I don't know if this works for CE.

              1 Reply Last reply
              0
              • B Offline
                B Offline
                blackbelt
                wrote on last edited by
                #7

                bq. I won’t call it a “leak”, cause it’s expected behavior to have the applications running in the background until other applications need that memory.

                I see, but Still, If my MainWindow shows this widget, when I close it, should all the momory allocated return to the system?

                1 Reply Last reply
                0
                • B Offline
                  B Offline
                  blackbelt
                  wrote on last edited by
                  #8

                  I use a QPixmap as Background Image but I allocate in on the stack. Should I take care of the QPixmap?

                  1 Reply Last reply
                  0
                  • A Offline
                    A Offline
                    andre
                    wrote on last edited by
                    #9

                    [quote author="blackbelt" date="1348478095"]I use a QPixmap as Background Image but I allocate in on the stack. Should I take care of the QPixmap?[/quote]
                    No. Items allocated on the stack are automatically deleted once they go out of scope.

                    1 Reply Last reply
                    0
                    • B Offline
                      B Offline
                      broadpeak
                      wrote on last edited by
                      #10

                      Try to use Qt's parent/child mechanism. That will automatically delete the child widgets. You can use it in the ctor or you can use it later with the .setparent() function. And if you have some layout, your widgets will be reparented automatically. Means: If the parent widget is go out of scope, your child widgets will be deleted without any intervention.

                      1 Reply Last reply
                      0
                      • A Offline
                        A Offline
                        andre
                        wrote on last edited by
                        #11

                        [quote author="broadpeak" date="1348479649"]Try to use Qt's parent/child mechanism. That will automatically delete the child widgets. You can use it in the ctor or you can use it later with the .setparent() function. And if you have some layout, your widgets will be reparented automatically. Means: If the parent widget is go out of scope, your child widgets will be deleted without any intervention.[/quote]
                        Only, QPixmap is not a QObject, and thus this mechanism can't be used here.

                        1 Reply Last reply
                        0
                        • B Offline
                          B Offline
                          broadpeak
                          wrote on last edited by
                          #12

                          [quote author="Andre" date="1348479951"]
                          [quote author="broadpeak" date="1348479649"]Try to use Qt's parent/child mechanism. That will automatically delete the child widgets. You can use it in the ctor or you can use it later with the .setparent() function. And if you have some layout, your widgets will be reparented automatically. Means: If the parent widget is go out of scope, your child widgets will be deleted without any intervention.[/quote]
                          Only, QPixmap is not a QObject, and thus this mechanism can't be used here.
                          [/quote]

                          How can be a pixmap on stack memory leaked?

                          Anyway, in WinCE with the close button you can't close the app, only put it in the background. If somebody would like to close the app, it can be made only with a button direct for this purpose (QCloseEvent, event->accept();).

                          1 Reply Last reply
                          0
                          • M Offline
                            M Offline
                            MichelS
                            wrote on last edited by
                            #13

                            If i recall that correctly you should react on the top-level window's OnHide event to shut your application manually down using @QCoreApplication::exit()@.

                            1 Reply Last reply
                            0
                            • B Offline
                              B Offline
                              blackbelt
                              wrote on last edited by
                              #14

                              bq. (QCloseEvent, event->accept();).

                              I already do that. If In my QWidget subclass I do not assign a parent (I call the super constructor with NULL as parameter), should I care to free all the memory allocated?

                              1 Reply Last reply
                              0
                              • B Offline
                                B Offline
                                broadpeak
                                wrote on last edited by
                                #15

                                [quote author="blackbelt" date="1348483366"]bq. (QCloseEvent, event->accept();).

                                I already do that. If In my QWidget subclass I do not assign a parent (I call the super constructor with NULL as parameter), should I care to free all the memory allocated?[/quote]

                                Yes. Every object what is created with new and has no parent (who is responsible for cleaning) must be deleted with the delete operator. If an object is created on the stack or has some parent relation, will be deleted by the system.

                                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