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

[ios] fix memory leak in Switch #18682

Merged
merged 1 commit into from
Nov 13, 2023
Merged

Conversation

jonathanpeppers
Copy link
Member

Context: #18365

Adding a parameter to the test:

[Theory("Handler Does Not Leak")]
[InlineData(typeof(Switch))]
public async Task HandlerDoesNotLeak(Type type)

Shows a memory leak in Switch, caused by the cycle

  • SwitchHandler ->
  • UISwitch.ValueChanged event ->
  • SwitchHandler

I could solve this problem by creating a SwitchProxy class -- the same pattern I've used in other PRs to avoid cycles. This makes an intermediate type to handle the events and breaks the cycle.

Still thinking if the analyzer could have caught this, issue filed at:

jonathanpeppers/memory-analyzers#12

Context: dotnet#18365

Adding a parameter to the test:

    [Theory("Handler Does Not Leak")]
    [InlineData(typeof(Switch))]
    public async Task HandlerDoesNotLeak(Type type)

Shows a memory leak in `Switch`, caused by the cycle

* `SwitchHandler` ->
* `UISwitch.ValueChanged` event ->
* `SwitchHandler`

I could solve this problem by creating a `SwitchProxy` class -- the same
pattern I've used in other PRs to avoid cycles. This makes an
intermediate type to handle the events and breaks the cycle.

Still thinking if the analyzer could have caught this, issue filed at:

jonathanpeppers/memory-analyzers#12
@jonathanpeppers jonathanpeppers added platform/iOS 🍎 memory-leak 💦 Memory usage grows / objects live forever labels Nov 10, 2023
@jonathanpeppers jonathanpeppers added this to the .NET 8 + Servicing milestone Nov 10, 2023
@jonathanpeppers jonathanpeppers marked this pull request as ready for review November 10, 2023 19:35
@jonathanpeppers jonathanpeppers requested a review from a team as a code owner November 10, 2023 19:35
@rmarinho rmarinho merged commit 2e286bf into dotnet:main Nov 13, 2023
47 checks passed
@jonathanpeppers jonathanpeppers deleted the SwitchLeaks branch November 13, 2023 14:32
@github-actions github-actions bot locked and limited conversation to collaborators Dec 14, 2023
@samhouts samhouts added the fixed-in-8.0.6 Look for this fix in 8.0.6 SR1! label Aug 2, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
fixed-in-8.0.6 Look for this fix in 8.0.6 SR1! memory-leak 💦 Memory usage grows / objects live forever platform/iOS 🍎
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants