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 leakage and memory management
QtWS25 Last Chance

Memory leakage and memory management

Scheduled Pinned Locked Moved General and Desktop
4 Posts 2 Posters 2.2k 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.
  • S Offline
    S Offline
    shahid.pk
    wrote on last edited by
    #1

    I would like devs here to suggest me topics that i should read for learning Qt's memory management mechanism.And look at this aap given below,will this aap delete the reserved memory for mainWindow when no reference is left or it will not do it automatically.If yes why?,if no again why?

    @#include <QtGui>
    #include <QApplication>

    int main (int argc,char *argv[])
    {

    QApplication qaap(argc,argv);

    QMainWindow *mainWindow = new QMainWindow;

    mainWindow->show();

    return qaap.exec();

    }@

    Love to learn....

    1 Reply Last reply
    0
    • M Offline
      M Offline
      mlong
      wrote on last edited by
      #2

      As the application ends, it will release the memory which was allocated in line 9. But that's just because it's the normal cleanup that an application does when it exits. Nothing Qt-specific.

      You could just as easily do a standard C++ new like:
      @
      int *foo = new int[1000];
      @

      and while it would be most proper to delete[] the memory when you were done, if it were still in existence when the app exited, it would be released by the OS as the program ended.

      Software Engineer
      My views and opinions do not necessarily reflect those of anyone -- living or dead, real or fictional -- in this universe or any other similar multiverse node. Void where prohibited. Your mileage may vary. Caveat emptor.

      1 Reply Last reply
      0
      • S Offline
        S Offline
        shahid.pk
        wrote on last edited by
        #3

        ok that is clear but i wanted to say that let it be like this if i am using a mainWindow in an aap and doing some other stuff to or you can say i am using the mainWindow in this aap for example
        @int main (int argc,char *argv[])
        {

        QApplication qaap(argc,argv);

        QMainWindow *mainWindow = new QMainWindow;

        mainWindow->show();
        //for example doing some network related stuff with values taken from the mainWindow
        // and main window is no longer needed.so right here what will qt do will it delete the mainWindow
        // pointer itself or not
        return qaap.exec();

        }@

        Love to learn....

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

          If you delete the main window before qaap.exec() is called, then nothing will ever happen, because the gui doesn't start up until QAplication::exec() is called.

          Software Engineer
          My views and opinions do not necessarily reflect those of anyone -- living or dead, real or fictional -- in this universe or any other similar multiverse node. Void where prohibited. Your mileage may vary. Caveat emptor.

          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