You’re leaking memory because you pass a “new” CCustomMenuBarModel object to the setMenuBar() method but it never gets deleted. Try storing your custom MenuBarModel object in a ScopedPointer in your MainWindow and then pass that to the setMenuBar() method.
when I setMenuBar(nullptr) in the ~MainWindow(),the exe was correct.
now i was puzzled…[quote=“ed95, post:2, topic:20433, full:true”]
Hi,
You’re leaking memory because you pass a “new” CCustomMenuBarModel object to the setMenuBar() method but it never gets deleted. Try storing your custom MenuBarModel object in a ScopedPointer in your MainWindow and then pass that to the setMenuBar() method.
You can still do both, the ScopedPointer keeps ownership and destroys the instance.
But something in the background seems to reference the menubarmodel, so if you keep the setMenuBar(nullptr); in the ~MainWindow() you should be fine… You can also define the destruction sequence by calling
~MainWindow() {
setMenuBar (nullptr); // removes the reference to the model
menubarModel = nullptr; // calls implicitly delete on the ScopedPointers target instance
}