Release File After MobileMapPackage OpenAsync

739
3
08-09-2018 03:48 PM
StephenDavis1
New Contributor II

I am using ArcGIS Runtime SDK 100.3 in UWP. I am using it to open a mobile map package, i.e. Esri.ArcGISRuntime.Mapping.MobileMapPackage.OpenAsync

There doesn't seem to be a way to delete the file once it goes out of scope. So, if I open it, load the map, display the map, remove the map, return from the method that used it (variables out of scope), then try to delete the file that was just used, I get a "file in use" exception. The map is completely out of scope, no layers are being used anywhere.

Is there a way to force the MobileMapPackage class to release the handle it has on a file without having to close the entire application? Sometimes we pull an mmpk into our application space for temporary use, open it, and then need to clean it up. To be clear, I am not looking to close the file while the map/layers are still in use/accessing local data.

Thanks

0 Kudos
3 Replies
MaraStoica4
Occasional Contributor

Take a look at how I've released the references to the mmpk to be able to delete it in the Offline Mapbook example app: 

https://github.com/Esri/mapbook-wpf/blob/4d58ce6e7bb7b6c0308cdc59ea445c6e8e931503/OfflineMapBook/Off...
0 Kudos
StephenDavis1
New Contributor II

Thanks for your example, that worked for me. Is there something similar for offline Vector Tiled Layers (vtpk)? I am also having trouble releasing the resources for those and deleting the files.

0 Kudos
MaraStoica4
Occasional Contributor

Try removing the vtpk layers from the map. This worked for me:

// set basemap to null and force garbage collection to release vector tiles
map.Basemap = null;
GC.Collect();
GC.WaitForPendingFinalizers();‍‍‍‍
0 Kudos