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

Memory leak while creating layers #32

Closed
AlexKven opened this issue Jun 3, 2020 · 1 comment · Fixed by #35
Closed

Memory leak while creating layers #32

AlexKven opened this issue Jun 3, 2020 · 1 comment · Fixed by #35

Comments

@AlexKven
Copy link

AlexKven commented Jun 3, 2020

Currently, when the AddLayer method on LeavletInterop.cs is run, it creates a new DotNetObjectReference and passes that to the JavaScript:

public static ValueTask AddLayer(IJSRuntime jsRuntime, string mapId, Layer layer) =>
    layer switch
    {
        TileLayer tileLayer => jsRuntime.InvokeVoidAsync($"{_BaseObjectContainer}.addTilelayer", mapId, tileLayer, DotNetObjectReference.Create(tileLayer)),
        MbTilesLayer mbTilesLayer => jsRuntime.InvokeVoidAsync($"{_BaseObjectContainer}.addMbTilesLayer", mapId, mbTilesLayer, DotNetObjectReference.Create(mbTilesLayer)),
        ShapefileLayer shapefileLayer => jsRuntime.InvokeVoidAsync($"{_BaseObjectContainer}.addShapefileLayer", mapId, shapefileLayer, DotNetObjectReference.Create(shapefileLayer)),
        Marker marker => jsRuntime.InvokeVoidAsync($"{_BaseObjectContainer}.addMarker", mapId, marker, DotNetObjectReference.Create(marker)),
        Rectangle rectangle => jsRuntime.InvokeVoidAsync($"{_BaseObjectContainer}.addRectangle", mapId, rectangle, DotNetObjectReference.Create(rectangle)),
        Circle circle => jsRuntime.InvokeVoidAsync($"{_BaseObjectContainer}.addCircle", mapId, circle, DotNetObjectReference.Create(circle)),
        Polygon polygon => jsRuntime.InvokeVoidAsync($"{_BaseObjectContainer}.addPolygon", mapId, polygon, DotNetObjectReference.Create(polygon)),
        Polyline polyline => jsRuntime.InvokeVoidAsync($"{_BaseObjectContainer}.addPolyline", mapId, polyline, DotNetObjectReference.Create(polyline)),
        ImageLayer image => jsRuntime.InvokeVoidAsync($"{_BaseObjectContainer}.addImageLayer", mapId, image, DotNetObjectReference.Create(image)),
        GeoJsonDataLayer geo => jsRuntime.InvokeVoidAsync($"{_BaseObjectContainer}.addGeoJsonLayer", mapId, geo, DotNetObjectReference.Create(geo)),
        _ => throw new NotImplementedException($"The layer {typeof(Layer).Name} has not been implemented."),
    };

However, since DotNetObjectReference must be disposed when no longer needed, this is a memory leak, since LeafletInterop doesn't keep track of these references and dispose them when the layer is removed. I will fix this in my PR.

AlexKven pushed a commit to AlexKven/BlazorLeaflet that referenced this issue Jun 3, 2020
…leak.

Mehigh17#29 Enables the Center and Zoom properties to set these properties on the map in the background.
Mehigh17#30 Adds a Bounds property to the map that is automatically kept up to date with the map bounds.
Mehigh17#32 Fixes a memory leak related to creating layers.
@Mehigh17 Mehigh17 linked a pull request Jun 6, 2020 that will close this issue
AlexKven pushed a commit to AlexKven/BlazorLeaflet that referenced this issue Jun 10, 2020
@Mehigh17 Mehigh17 linked a pull request Jun 10, 2020 that will close this issue
Mehigh17 added a commit that referenced this issue Jun 10, 2020
#32 Fixed memory leak when creating layers
@chucker
Copy link
Contributor

chucker commented Jun 11, 2020

Hmmm, I ran into a "item with same key already exists" exception. I haven't looked into how layer IDs (used as keys here) get generated, but perhaps they get incorrectly reused, or maybe there's a concurrency issue here.

FrankHellwich added a commit to FrankHellwich/BlazorLeaflet that referenced this issue Oct 2, 2023
…initialization from AlexKven-deature/settable-properties
FrankHellwich added a commit to FrankHellwich/BlazorLeaflet that referenced this issue Oct 2, 2023
…initialization from AlexKven-deature/settable-properties
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants