var pMd = new MapDocumentClass();
pMd.Open(RevisionState.CurrentBackupMXDPath_.BSValue());
var pMap = pMd.Map[0];
pMd.Close();
Marshal.FinalReleaseComObject(pMap);
pMap = null;
Marshal.FinalReleaseComObject(pMd);
pMd = null;
GC.Collect();
GC.WaitForPendingFinalizers();
Please see the code above. I found that memory usage increased so much while executing var pMap = pMd.Map[0];. However, I cannot release these memory even I run all the rest of the statement. May I know how can I release IMap reference? Thanks!
Maybe try calling Collect() and WaitforPendingFinalizers before closing, as described here:
Thank you @KirkKuykendall1
Have tried just now but no luck... Memory usage of this statement cost me 50000KB of memory. Even I run the rest statements in this order...
var pMd = new MapDocumentClass();
pMd.Open(RevisionState.CurrentBackupMXDPath_.BSValue());
var pMap = pMd.Map[0];
GC.Collect();
GC.WaitForPendingFinalizers();
pMd.Close();
Marshal.FinalReleaseComObject(pMap);
pMap = null;
Marshal.FinalReleaseComObject(pMd);
pMd = null;
The memory usage drops only ~1000KB 😞
Anyone help me out? 😞
At the very end of all of my projects in "Dispose" of my form with the map I always include
ESRI.ArcGIS.ADF.COMSupport.AOUninitialize.Shutdown();
This is in the ESRI.ArcGIS.ADF.Local resource.
I have never had an issue and I don't need to do the garbage collecting and marshalling.
Brent Hoskisson
This is because you are playing with a short-run process. For me, I am working with a long run process which lives as long as the lifetime of an ArcMap session.
What is in the map? Do you have basemaps displaying, layers linking to say datasets stored in ArcGIS Online or ArcServer that maybe maintaining a link thus not allowing memory to be released? I would try a simple map with say a locally stored shapefile as a test. See if you can track the problem down.