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

Resources not get disposed of in SortableList.razor #14

Open
Owenll66 opened this issue Oct 6, 2024 · 0 comments
Open

Resources not get disposed of in SortableList.razor #14

Owenll66 opened this issue Oct 6, 2024 · 0 comments

Comments

@Owenll66
Copy link

Owenll66 commented Oct 6, 2024

The file is missing implementing IAsyncDisposable/IDisposable. The blazor framework won't recognize the Dispose() method and it will never get executed.

I think it needs

@implements IAsyncDisposable

The IJSObjectReference module needs to get disposed of too, and we need a private field for it.

private IJSObjectReference? module;

protected override async Task OnAfterRenderAsync(bool firstRender)
{
    if (firstRender)
    {
        selfReference = DotNetObjectReference.Create(this);
        // Should module get disposed of as well?
        module = await JS.InvokeAsync<IJSObjectReference>("import", "./Shared/SortableList.razor.js");
        await module.InvokeAsync<string>("init", Id, Group, Pull, Put, Sort, Handle, Filter, selfReference, ForceFallback);
    }
}

And finally

public async ValueTask DisposeAsync()
{
    selfReference?.Dispose();
    await module!.DisposeAsync();
}
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

1 participant