extreme001
extreme001

Reputation: 363

C++ wxWidgets Gui-App stays in memory after closing it

The subject says it all. After i closed my app, it stays in the list of processes with some memory. I tried google perf tools and hours of debugging to find the leak.

Are there other tools to test it and find the problem?

Thank you.

Upvotes: 1

Views: 867

Answers (3)

ravenspoint
ravenspoint

Reputation: 20457

My guess is that you have closed the top level window, and thus all its child windows, but you have not closed the app itself.

This does not happen if your program is arranged in a 'normal' way, but if you have, deliberately or by accident, used an unusual arrangement this can happen.

Fixing it, of course, depends on how exactly you have arranged your code. However, here is a suggestion to begin.

The usual way to close the app is to call wxApp::OnExit() which normally occurs when the top level window closes.

Do you have your own class, derived from wxApp? Do you have an override of OnExit()? If not, then make it so and use the debugger to check whether or not it is being called. If it is not being called, work out how to ensure that it is called.

Another idea: use the following to check that your top level window will close the app

bool wxApp::GetExitOnFrameDelete() const

Returns true if the application will exit when the top-level window is deleted, false otherwise.

If this return false, use the corresponding set to make it so.

A 3rd idea: The application will not exit while there are any top level windows open. So perhaps you have another top level window that is minimized or invisible but has not been closed? Any wxDialog or WxFrame or window derived from these is a top level window and will prevent the application from closing.

A 4th idea: Do you have any globals or attributes of the application object, whose destructors could enter an endless loop? These destructors are called after the windows are destroyed and if one of them does not return you would see the behaviour you describe.

Upvotes: 1

extreme001
extreme001

Reputation: 363

Yes...problem solved. A TopLevelWindow that was not destroyed. A Memory Leak....stupid mistake.

Upvotes: 1

Rui Curado
Rui Curado

Reputation: 949

You may try to look at wxWidget's sample folder. You'll find lots of small but complete applications that contain the full init/exit application cycle.

Inspect some samples and compare with your app's workflow.

Upvotes: 1

Related Questions