title: QT - Main Widget - Stack or Heap?
body: <p>I am a little confused on whether I should prefer to initialize my main widgets on the stack or on the heap. In "C++ GUI Programming with QT 4," main widgets are initialized on the stack. Before I say more, I will explain what I mean:</p>
  
  <pre><code>int main(int argc, char *argv[])
  {
      QApplication app(argc, argv);
      MainWindow mainWin;
      mainWin.show();
      return app.exec();
  }
  </code></pre>
  
  <p>Now, perhaps this is simply because it is safer, perhaps it is because they don't want to confuse readers about memory allocation in QT. Leaving out any deletes on objects inheriting from QObject certainly does allow readers to "forget" memory-management with QT objects. But, my question is, should we prefer that method, or the following:</p>
  
  <pre><code>int main(int argc, char *argv[])
  {
      QApplication app(argc, argv);
      MainWindow* mainWin = new MainWindow;
      mainWin-&gt;show();
      int execReturn = app.exec();
      delete mainWin;
      return execReturn;
  }
  </code></pre>
  
  <p>The main reason I bring this question is I normally prefer to follow a pattern with choosing heap vs stack:</p>
  
  <ul>
  <li>If the item is large - <strong>Heap</strong></li>
  <li>If the item is long-term - <strong>Heap</strong></li>
  <li>Otherwise - <strong>Stack</strong></li>
  </ul>
  
  <p>Now, I guess my question boils down to two questions:</p>
  
  <ul>
  <li>Is QWidget large to the point where I should fear stack-overflows?</li>
  <li>How large is the stack for the average application? When should I fear for overflowing the stack (Other than obviously recursive functions)?</li>
  </ul>
  
  <p>I realize it is unlikely that QWidget itself causes a stack-overflow, but of course this will be on top of any other stack usage my application may have.</p>