Hi the problem is common as far as I know from reading post from this and other forums(memory usage for arcgis). I'm developing a add-in for ArcMap that checks electricity flow in Geometric Network. I've created a loop for over 14 000 start points for my analysis. I'm using Utility Network Analyst and the FindFlowElements method, the algorithm is preety simple:1. Get Geometric Network IDs for starting point(FCID, FID, subID)2. Configure Geometric Network3. FindFlowElements -> as a result i get junctionEIDs and edgeEIDs4. Create selection from the result5. Analyze the selection 6. Log info7. Clearing the result8. Clearing the flags for network utility9. Clearing the selection for map10. Partial refresh11. Marshal.FinalReleaseComObject(traceFlowSolver); // testing it because of the out of memory exceptionand again from the point 1 for next point.So when we tested this we encountered a lot of errors. I have the log info we are writing to txt file it will be easier to illustrate the problem with example:INFO 2013-03-19 12:56:12,302 â?? Called FindFlowElements method 1374 time(s)Number of objects in List<T> SN = 1316, memory usage = 0,06808 MBNumber of objects in List<T> nN = 10068, memory usage = 0,43913 MBStation number 7545 Process name: ArcMap -> memory use 834,5586 MB || GC TotalMemory -> 80,0527 MBProcesses list:IEXPLORE ||memory use-> 31,6836 MBFSM32 ||memory use-> 15,6992 MBSVCHOST ||memory use-> 26,4336 MBEXPLORER ||memory use-> 85,4766 MBSMSVCHOST ||memory use-> 37,5313 MBDSTERMSERV ||memory use-> 27,0664 MBFSSM32 ||memory use-> 167,2422 MBSVCHOST ||memory use-> 48,6758 MBSVCHOST ||memory use-> 82,5117 MBFSHDLL32 ||memory use-> 52,4531 MBBCU ||memory use-> 85,0273 MBORACLE ||memory use-> 771,1250 MBSPLWOW64 ||memory use-> 15,6484 MBIEXPLORE ||memory use-> 15,7031 MBARCMAP ||memory use-> 964,2070 MBSEARCHINDEXER ||memory use-> 50,6445 MBTNSLSNR ||memory use-> 36,6602 MBWINWORD ||memory use-> 22,3398 MBFSGK32 ||memory use-> 15,4453 MBSOFFICE.BIN ||memory use-> 16,2188 MBAUDIODG ||memory use-> 18,5859 MBIEXPLORE ||memory use-> 19,3359 MBSPOOLSV ||memory use-> 17,4063 MBWMPNETWK ||memory use-> 30,1172 MBSVCHOST ||memory use-> 29,7500 MBSVCHOST ||memory use-> 234,8750 MBDWM ||memory use-> 45,6406 MBSVCHOST ||memory use-> 25,8594 MBCONNECT.SERVICE.CONTENTSERVICE ||memory use-> 51,8594 MBMemory usage sum = 2911,0120 MB=================================================================================================INFO 2013-03-19 12:56:14,954 â?? Called FindFlowElements method 1375 timesNumber of objects in List<T> SN = 1316, memory usage = 0,06808 MBNumber of objects in List<T> nN = 10072, memory use = 0,43931 MBStation number 7397 Process name: ArcMap -> memory use 838,7539 MB || GC TotalMemory -> 84,8050 MBProcesses list:xxxxMemory usage sum = 2899,1410 MBThe FindFlowElementos method was called 1375 times(14 000 expected...) and ArcMap already uses ~840 MB(when it reaches ~2GB arcmap throws an error) of memory and it's growing with every iteration. Sometimes it drops with few MB but no to often so i will propably have to do the cleaning manually, but the question is how?I will explain now how i calculated/got the memory usage:1.For ArcMap:
private const float mbyte = 1048576;
Process proc = Process.GetCurrentProcess();
string privMemSize = (proc.PrivateMemorySize64 / mbyte).ToString("0.0000");
2.For Garbage Collector:
string gcTotalMem = (GC.GetTotalMemory(false) / mbyte).ToString("0.0000");
3.Memory usage for Lists<T> I'm calculating with method I took from StackExchange:
private static string GetObjectSize(object TestObject)
{
try
{
BinaryFormatter bf = new BinaryFormatter();
MemoryStream ms = new MemoryStream();
byte[] Array;
bf.Serialize(ms, TestObject);
Array = ms.ToArray();
return ((float)Array.Length / mbyte).ToString("0.00000");
}
catch (Exception ex)
{
log.Error("========================================================================\n"
+ex.Message + "\n" + ex.StackTrace + "\n"
+ "========================================================================\n");
return "error";
}
}
The question is how I can handle the increasing memory usage for ArcMap.exe? Anyone got idea?