rungwiroon / BlazorGoogleMaps

Blazor interop for GoogleMap library
MIT License
319 stars 102 forks source link

Dispose question #266

Closed ryanbuening closed 1 year ago

ryanbuening commented 1 year ago

Thanks for this great library! Given the code-behind class below, is it necessary to implement IDisposable and call Dispose() on GoogleMap?

public partial class UnassignedClaims : IDisposable
{ 
    private GoogleMap _map = new();
  ...
    public void Dispose()
    {
        _map.Dispose(); // necessary?
    }
}

GoogleMap looks like the following

namespace GoogleMapsComponents
{
    public class GoogleMap : MapComponent, IDisposable
    {
        ...
        void IDisposable.Dispose()
        {
        }
    }
}
valentasm1 commented 1 year ago

I dont know where you got such code for library. It is a bit different in reality. https://github.com/rungwiroon/BlazorGoogleMaps/blob/master/GoogleMapsComponents/GoogleMap.razor#L82

Despite that component lifecycle in blazor automatically call dispose, so it is enough just create implementation if needed. https://learn.microsoft.com/en-us/aspnet/core/blazor/components/lifecycle?view=aspnetcore-5.0#component-disposal-with-idisposable-and-iasyncdisposable

ryanbuening commented 1 year ago

Ahh, I am on 3.0.5.0. It looks like some changes were made with Dispose() in recent versions. Thanks for the reply.