oran
10-03-2008, 08:55 AM
I'm running batches of zipcodes thru MP2006/2009 to calculate driving distances between them. Automated via C# which sets Waypoints, gets results and moves on to the next pair of zips.
Sample code:
MapPoint.ApplicationClass objApp = new MapPoint.ApplicationClass();
MapPoint.Map objMap = null;
objApp.Visible = false; //make map not show or launch window
objMap = objApp.ActiveMap;
MapPoint.FindResults findResults1 = objMap.FindResults(braddr);
MapPoint.FindResults findResults2 = objMap.FindResults(custaddr);
objMap.ActiveRoute.Waypoints.Add(objMap.FindResult s(braddr).get_Item(ref obj1), "");
objMap.ActiveRoute.Waypoints.Add(objMap.FindResult s(custaddr).get_Item(ref obj1), "");
objMap.ActiveRoute.Calculate();//calculates map and route
distance = (objMap.ActiveRoute.Distance * 2);//doubled for roundtrip numbers
objMap.ActiveRoute.Clear();//clears out route info
objApp.ActiveMap.Saved = true;//remove pesky popup requesting you to save map
objApp.Quit();//make mappoint.exe close -- takes a few seconds (in the background)
objApp = null;
Pretty standard stuff. But the constant opening and closing of Mappoint makes it slow and MP doesn't always get closed before it's asked to open again.
So I rewrote the code so I open MP once, then loop thru my pairs of zips and when finished close MP.
This works fine and is faster BUT...
With Task Manager open I can see MP eating up RAM, about 2k-5K per calculation and despite telling it to CLear the route I NEVER see the memory used go down , it just keeps incrementing upwards. When it hits 450M it stops because my sever says "enough!"
Any ideas on how to make it release the memory it's chewing up?
Sample code:
MapPoint.ApplicationClass objApp = new MapPoint.ApplicationClass();
MapPoint.Map objMap = null;
objApp.Visible = false; //make map not show or launch window
objMap = objApp.ActiveMap;
MapPoint.FindResults findResults1 = objMap.FindResults(braddr);
MapPoint.FindResults findResults2 = objMap.FindResults(custaddr);
objMap.ActiveRoute.Waypoints.Add(objMap.FindResult s(braddr).get_Item(ref obj1), "");
objMap.ActiveRoute.Waypoints.Add(objMap.FindResult s(custaddr).get_Item(ref obj1), "");
objMap.ActiveRoute.Calculate();//calculates map and route
distance = (objMap.ActiveRoute.Distance * 2);//doubled for roundtrip numbers
objMap.ActiveRoute.Clear();//clears out route info
objApp.ActiveMap.Saved = true;//remove pesky popup requesting you to save map
objApp.Quit();//make mappoint.exe close -- takes a few seconds (in the background)
objApp = null;
Pretty standard stuff. But the constant opening and closing of Mappoint makes it slow and MP doesn't always get closed before it's asked to open again.
So I rewrote the code so I open MP once, then loop thru my pairs of zips and when finished close MP.
This works fine and is faster BUT...
With Task Manager open I can see MP eating up RAM, about 2k-5K per calculation and despite telling it to CLear the route I NEVER see the memory used go down , it just keeps incrementing upwards. When it hits 450M it stops because my sever says "enough!"
Any ideas on how to make it release the memory it's chewing up?