How can I stop accessing a .mmpk without closing my app?

453
2
10-15-2018 09:24 AM
KeithLarson1
MVP Alum

Hello,

I am making a QML application and it loads .mmpk files into a MobileMapPackage to display downloaded data. I have a page where it displays all of the availabe files and allows the user to switch between different .mmpk's. I do this by setting the MobileMapPackage to a new MobileMapPackage item and set the path to the new file. I also allow renaming and deleting of files, given that they aren't currently opened. The problem is when I try to delete or rename a file that I had previously opened since the app was opened, it fails because, as far as I can tell, the .geodatabase file within the .mmpk is still being accessed by my application. I was able to tell, because the recursive delete of the .mmpk deletes everything except for that .geodatabse file. In my testing of this problem, I can clearly see that it is updating the MobileMapPackage and I even tried manually calling the garbage collector, gc(), but that still didn't allow me to properly delete the file. Does anyone know how I could release control from the file?

Thanks,

Keith

0 Kudos
2 Replies
LucasDanzinger
Esri Frequent Contributor

This is tough since QML is a managed language. The trick is to make sure that all references have gone out of scope. Otherwise, the GC won't clean it up. If you are suspicious that it is the geodatabase that still has references to it, you could try calling the close method on it directly - Geodatabase QML Type | ArcGIS for Developers 

This will close off references and allow you to delete the geodatabase. But if you still have a bunch of layers, tables, and maps created and referenced inside the mmpk, this will be hard to clear out in QML. Does Geodatabase::close help you at all?

0 Kudos
KeithLarson1
MVP Alum

Hey Lucas,

Thanks for the quick reply. I don't believe I can close the .geodatabase file because that is generated with the .mmpk and I never directly create a Geodatabase from that file. My guess is that the file is being used to set the layers for the map(s) that are in the MobileMapPackage item, but I don't think I can get a reference to that Geodatabase. I would think that when I overwrite the reference to the MobileMapPackage everything behind the scenes would get garbage collected, but I could be wrong.

0 Kudos