Select to view content in your preferred language

How to free/release/unload/uncouple Raster from layer? (v100.4 WPF)

1048
2
08-02-2019 10:30 AM
KeithGemeinhart1
Regular Contributor

Here is what I would like to do:

  1. Create a raster layer from a file
  2. Add the layer to the map
    var rlayer = new RasterLayer(new Raster("C:/...../myraster.tif");
  3. Regenerate the raster (same filename if possible, but I have some flexibility)
  4. Refresh the raster layer with the newly updated raster file (so that the map is updated)

My problem is that the raster file is still in use (presumably a reference held by the layer). So I can't delete the file or rename it. I tried a few things to try to uncouple the raster from the layer, but no luck. For example ...

var layers = mapVm.Map.OperationalLayers;
var raster = myRasterLayer.Raster;

layers.Remove(layer);
raster = null;
layer = null;‍‍‍‍‍‍

System.GC.Collect();

I even tried to force garbage collection. I think that may have worked once or twice, but I can't replicate it reliably.

I also tried the local server approach in the ArcGISRuntime.WPF.Samples.DynamicWorkspaceRaster

sample, but same result.

Any advice? Maybe I need to take a different approach?

0 Kudos
2 Replies
KeithGemeinhart1
Regular Contributor

Quick bit of additional info. I tried this using LocalServer as it is done in the Dynamic Workspace Raster from the SDK Samples App, and I get similar behavior. The local server holds a reference to the raster even when a new/different raster file is chosen.

0 Kudos
RachaelSmith1
New Contributor

I had a similar problem trying to delete files even after clearing the operational layers. Looking through the documentation, I found a note on GeoPackage.Close() saying that only after closing the geopackage can an underlying file be deleted/renamed etc. Adding a call to this got my system working. Hope this helps.

0 Kudos