Question about memory management
Hi, I get confused about auto release c++ object.
For example,
QApplication app(argc, argv);
QLabel * label = new QLabel(QObject::tr("Hello Qt!"));
QWidget *w = new QWidget;
label->setParent(w);
w->show();
app.exec();
delete w;
delete label; // this label point is wild pointer!
return 0;
the code as above will be crash, because you should delete label first.
my question is:
in haskell code:
toGc label -- do not need to delete label, bcz when delete w, label is automatically deleted, just illustrate the problem
toGc w
can garbage collector guarantee that label will be delete before w?
Edited by zhufei