I have created a temporary File GDB-based scratch workspace as follows:
var factoryType = Type.GetTypeFromProgID("esriDataSourcesGDB.FileGDBScratchWorkspaceFactory"); var factory = (IScratchWorkspaceFactory)Activator.CreateInstance(factoryType); var workspace = factory.CreateNewScratchWorkspace();
Running this code creates a File GDB in my user profile's
Esri's documentation claims that:
"Workspaces created by
IScratchWorkspaceFactory.CreateNewScratchWorkspacewill be automatically deleted when the last reference to them is released."
However, this does not happen. Even after my application terminates, and even though all ArcGIS application have been closed, the File GDB remains in my temporary folder.
I have tried explicitly releasing the workspace:
But that does not delete the temporary File GDB either. Trying to additionally delete the directory will not work either, because some file in the File GDB directory is still in use:
var path = workspace.PathName; Marshal.FinalReleaseComObject(workspace); System.IO.Directory.Delete(path, recursive: true);
Am I doing something wrong? And if so, what? How do I best deal with scratch workspaces that are no longer in use?
Is the documentation simply incorrect on this point?
Or will Windows regularly delete that temporary folder and thus delete the scratch File GDB? (This does not seem to be the case.)