ThinkGeo.com    |     Documentation    |     Premium Support

How to cleanup Layer

Hi, I was wondering if there is any way to cleanup a deleted layer?

Let me explain: In our program, users can create their own layer types from files and display them.
They can also delete those layers. I have noticed that after deleting a layer, the index file is not freed (says it is still in use when creating a layer that uses the same file).

So I was wondering - what is the correct way of disposing of a layer?

Currently we do the following:

public async Task RemoveLayerFromMap(IViewerLayer viewerLayer)
{
    if (Overlays.Contains(StaticOverlay))
    {
        if (StaticOverlay.Layers.Contains(viewerLayer.LayerName))
        {
            StaticOverlay.Layers.Remove(viewerLayer.LayerName);

            await RefreshAsync(StaticOverlay);
        }
    }
}

with StaticOverlay being a LayerOverlay

If it is a Layer, call layer.Close()
if it is an AsyncLayer, call layer.CloseAsync()

If it’s a custom Layer/AsyncLayer, make sure to override the CloseCore()/CloseAsyncCore() and release the resources there.

1 Like