PDA

View Full Version : MP eats up Ram with multiple routes despite clearing.



oran
10-03-2008, 09: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?

Winwaed
10-03-2008, 03:45 PM
This is to do with garbage disposal. MapPoint is pretty lazy when it comes to garbage disposal and will do what you describe until physical memory becomes a problem. Considering MapPoint is primarily designed for GUI users, this makes sense. (although a manual GC call in the API would be useful!).

One solution is to minimize and maximize MapPoint. You have to do this through the Windows API - it doesn't work if you use the app windowstate property.

<shameless plug for one of my products>
My MPMileage program does batch MapPoint route calculation as well - start/end points are specified in a database. On a modern PC, I bet it is quicker than your code! :-)
MPMileage: Batch calculate mileages with Microsoft MapPoint (http://www.mpmileage.com)


Richard

dthoma
10-14-2008, 10:31 AM
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?

Just a thought ... could you count the number of zip pairs you have and divide that by a number and when those numbers hit close MP and reopen it?

-or-

I am not this advanced yet ... there probably is a way to look at the process and when it gets over 250M shut down MP and restart it, which would be a better way of doing it. ([vb.net] monitor process' memory usage - Neowin Forums (http://www.neowin.net/forum/index.php?showtopic=613769)) ... haven't tried it ... shot in the dark.

obviously the code would have to run along side the code you listed. which would slow things up a bit.

Winwaed
10-15-2008, 09:08 AM
Counting successful routes and restarting works.

At what point the restart occurs is a matter of choice. As memory is used up, MapPoint runs slower. But the restart process itself takes extra time. When is the optimum?


Richard