Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How does winrt::auto_revoke not result in memory leaks? #1428

Closed
amtopel opened this issue Jul 27, 2024 · 1 comment
Closed

How does winrt::auto_revoke not result in memory leaks? #1428

amtopel opened this issue Jul 27, 2024 · 1 comment

Comments

@amtopel
Copy link

amtopel commented Jul 27, 2024

Version

No response

Summary

This isn't a bug. Just a question. According to the docs, an auto event revoker will revoke when it goes out of scope. The docs provide this example:

struct Example : ExampleT<Example>
{
    Example(winrt::Windows::UI::Xaml::Controls::Button button)
    {
        m_event_revoker = button.Click(
            winrt::auto_revoke,
            [this](IInspectable const& /* sender */,
            RoutedEventArgs const& /* args */)
        {
            // ...
        });
    }

private:
    winrt::Windows::UI::Xaml::Controls::Button::Click_revoker m_event_revoker;
};

But in this case m_event_revoker won't go out of scope until the class is deleted. The class won't be deleted until all references go to zero. And references won't go to zero until the event handler has been revoked. So shouldn't this result in a circular reference and memory leak? Or maybe I'm missing something.

Reproducible example

No response

Expected behavior

No response

Actual behavior

No response

Additional comments

No response

@amtopel amtopel closed this as completed Jul 27, 2024
@sylveon
Copy link
Contributor

sylveon commented Jul 28, 2024

There is no strong reference in this case, this in the lambda capture is a raw pointer.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants