locked
Why is the destructor not called?

    Question

  • When i do this twice:

    Window::Current->Content = ref new MainPage();

    Window::Current->Content = ref new MainPage();

    the destructor of the first call should be called. But this does not happen

    When i declare this class:

    public ref class Person
     {
     public:
      Person();
      ~Person();
     };

    and do this:

    Person^ p = ref new Person();

    p = ref new Person();

    the destructor for the first call gets called.

    Wednesday, February 22, 2012 1:38 PM

All replies

  • It seems to have something to do with the inheriance:

    partial ref class MainPage: public Windows::UI::Xaml::Controls::UserControl, ...

    but still the question: why is the destuctor not called?

    Thursday, February 23, 2012 7:08 AM
  • Could you please file a bug on this? Even if this is the expected behavior, we should have some documentation to explain this behavior.

    Here is the bug filing instructions:

    Thank you for posting your feedback, we want to make sure we
    get the right info including your log files.  Can you also submit feedback
    using the Windows Feedback Tool from the Connect Site associated with your
    Windows Developer Preview program? If you’re an
    MSDN subscriber, the information on how to join the Connect program is included
    on the download page where you installed Windows Developer Preview. 
    There’s a link to the Connect site and an invitation code that you can click on
    to join using a Windows Live ID account. If you’re not an MSDN subscriber
    follow this limited use link
    to join the Connect program and then follow the steps here

    Thanks,

    -David


    Tuesday, February 28, 2012 4:16 PM
    Moderator
  • Could you please file a bug on this? Even if this is the expected behavior, we should have some documentation to explain this behavior.


    In the meanwhile, could you explain this behavior? What is the pattern here?
    Wednesday, February 29, 2012 7:21 AM
  • Have you had a chance to try this on the Consumer Preview to see if the behavior has changed since DP?

    Friday, March 2, 2012 4:48 PM
    Moderator
  • I had a chance to test this on CP today. I was still running into issues, different than //build/ but still not working as expected.

    I created a bug to track this. I would expect the destructor to be executed as in any other class. If I hear otherwise, I'll be sure that detail is posted here.

    Thanks,

    -David

    Saturday, March 3, 2012 2:34 AM
    Moderator
  • For me the destructors of UI Objects now are called.

    but i have a other question in this direction:

    http://social.msdn.microsoft.com/Forums/en-US/winappswithnativecode/thread/9eb10013-37ed-49ef-9f04-64b973779021

    • Proposed as answer by Chris Guzak Wednesday, March 14, 2012 5:28 AM
    Thursday, March 8, 2012 10:43 AM