isrepeat-0264 avatar image
0 Votes"
isrepeat-0264 asked isrepeat-0264 commented

[UWP][C++/CX] Page destructor not called after close app why?

I have following code:

 public ref class MainPage sealed
         int a = 1;
         int b = 2;

Why the destructor MainPage is not called when I close app?

However when change MainPage on other Page due to Navigate destructor MainPage is called.
It's normal for uwp not calling destructor current page when we closing app?
How i can foreced call destructor if i want?

· 6
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

How did you check it?

0 Votes 0 ·

I put breakpoint in destructor and programm never entered there ...

0 Votes 0 ·

Could you please tell me your concerns? Does the destructor lead to unexpected behavior when you closed your app?

0 Votes 0 ·

I was just expecting the destructor body will execute when I close app. But, as I understand it, Windows exits the application by calling something like "exit(0);" and, therefore, no destructors are executed. I just tested it on a small console app by calling "exit(0);" before "return 0;" in main() and behavior was similarly.

0 Votes 0 ·

It looks like it's by design. Did you call delete manually to test whether the destructor works? Check this: Destructors.

0 Votes 0 ·

Yes, the destructor C++/CX normal works if use delete or scope-life.
As I wrote above: "However when change MainPage on other Page due to Navigate destructor MainPage is called."

It looks like it's by design.

Yes, maybe.

0 Votes 0 ·

0 Answers