Community of VE/MapPoint Users and Developers
This is a discussion on base.Dispose() hung the program within the MapPoint 2006/2009 Discussion forums, part of the Map Forums category; On a window with MapPoint 2004 I found my program hanging and needing to be reboored. In the automaticaly generated ...
| |||||||
| Register | Blogs | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| |||
| base.Dispose() hung the program In the automaticaly generated code by Visual Studio, in the Dispose() function, it hung on base.Dispose(). I also noticed the map had previously displayed the entire map of North America, wherease normally it displays a much smaller area, a few minles accross. What kind of error could have caused this to crash like that? The program simply hung at base.Dispose(). Hope to hear from you. Thanks, BobFromBoston |
| |||
| Re: base.Dispose() hung the program
Could I have a memory leak? I do nothing to dispose of these objects. I'm a C++ developer turned C# developer, and thought these things were handled for me. But now I wonder if I need to explictly dispose of each pushpin when I dispose of the window. Is that true? BobFromBoston. |
| |||
| Re: base.Dispose() hung the program
Here is the Dispose function generated by Visual Studio 2005. Is this enough to clean up the MapPoint resources? BobFromBoston protected override void Dispose( bool disposing ) { if( disposing ) { if(components != null) { components.Dispose(); } } base.Dispose( disposing ); } |
| |||
| Re: base.Dispose() hung the program
Hi, I don't know why it hangs but possible there is a lot to clean up and it is done at program termination. But cleaning up takes memory, so possible that's the reason. You need to dispose everything your create yourself. Only the things that are dropped on a form or so you don't dispose. If you don't then it will look as if you have memory leaks and your program will terminate very slow. About your question of pushpins, I don't know. but I do delete them always. It is a good habitude to destroy what you don't need anymore. This is an example of a class using mappoint activex control. it also demonstrate the Dispose method (C#): Code: public Foo(Control Owner)
{
owner = Owner;
mp = new AxMapPoint.AxMappointControl();
owner.Controls.Add(mp);
}
~Foo()
{
Dispose(false);
}
public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}
protected virtual void Dispose(bool disposeManagedResources)
{
if (!disposed) {
if (disposeManagedResources) {
map.Saved = true;
owner.Controls.Remove(mp);
mp.Dispose();
mp = null;
}
disposed = true;
}
}
__________________ rgds, Wilfried Mestdagh www.mestdagh.biz MapPoint coding demo Order MapPoint 2009 with Routing and User Tools Spreadsheet |
| ||||
| Re: base.Dispose() hung the program
Yes Disposing always seems more complicated than it should be. Wilfried's implementation looks about right. A good C# book should also cover how to implement IDisposable. You have to make sure you don't dispose thinks that have been deleted or already disposed / etc. Richard
__________________ Winwaed Software Technology LLC http://www.winwaed.com See http://www.mapping-tools.com for MapPoint Tools Pre-Order MapPoint 2009 today: http://www.mapping-tools.com/mappoint2009 |
| |||
| Re: base.Dispose() hung the program
I have functions inside my program which access a MapPoint map object that is always present in my program, sine the same window is always open. Is the method (shown below) of clearing the route acceptable for memory management? I clear the route before I start putting the two new waypoints into it. Is this the best way to clear this memory used? Is this a memory leak? I have some sort of memory leak with MapPoint that I am trying to find. Is there a need for me to call the Delete() method associatd with each waypoint as well? Or is calling mpRoute.Clear(); sufficient? Thanks, Bob public static string GetMilesAndMinutes( Handles handles, Coordinates pointA, Coordinates pointB ) { string returnStr = null; MapPoint.Route mpRoute = null; MapPoint.Map mpMap = handles.MapPointMap; mpRoute = mpMap.ActiveRoute; mpRoute.Clear(); MapPoint.Location locA = mpMap.GetLocation( pointA.Latitude, pointA.Longitude, 100 ); if ( locA == null ) { return null; } mpRoute.Waypoints.Add( locA, "locA" ); MapPoint.Location locB = mpMap.GetLocation( pointB.Latitude, pointB.Longitude, 100 ); if ( locB == null ) { return null; } mpRoute.Waypoints.Add( locB, "locB" ); mpRoute.Calculate(); double thisMinutes = Math.Round( mpRoute.DrivingTime * 24 * 60, 1); double thisMiles = Math.Round( mpRoute.Distance, 2); double comparisonMiles = mpMap.Distance( locA, locB ); returnStr = thisMiles.ToString() + "," + thisMinutes.ToString(); return returnStr; } |
| |||
| Re: base.Dispose() hung the program
Hi, As far as I know is clearing the route sufficient.
__________________ rgds, Wilfried Mestdagh www.mestdagh.biz MapPoint coding demo Order MapPoint 2009 with Routing and User Tools Spreadsheet |
![]() |
| Tags |
| basedispose, hung, program |
| ||||
| Posted By | For | Type | Date | |
| Latitude / Longitude DMS -> Decimal Converter - MP2K Magazine | This thread | Refback | 01-24-2008 11:52 AM | |
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
| |
| ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Base Meridian/Township/Range/Section data | Anonymous | MapPoint 2006/2009 Discussion | 2 | 3 Hours Ago 04:40 PM |
| Reverse Geocode base on Zip? | DotNetAllDay | MapPoint Web Service and Virtual Earth | 0 | 10-12-2007 05:04 PM |
| MS Access-single data base/multiple Map categories | teishin | MapPoint 2006/2009 Discussion | 1 | 01-05-2007 08:35 AM |
| Map points base map | KevP | MapPoint 2006/2009 Discussion | 1 | 10-18-2005 05:36 PM |
| Update base map data using those in MS Steets & Trips | Anonymous | Wish List | 0 | 12-18-2002 10:40 AM |
Cheap flights to Majorca
Majorca has got a little something for everyone. As well as the legendary nightlife there are historical areas to explore. Check it out!
Cruise Travel Agent
Book your cruise with Travel Counsellors. We are an award winning travel agent and can help plan your perfect cruise.
Flights Canada
Our search results will show you a selection of airlines, travel agents and tour operators offering cheap flights to Canada. See for yourself who has the cheapest deals.
Holidays to Mauritius
Visit the paradise island in your holidays to Mauritius. Enjoy the friendliness of the locals, the warm of the sun and the beauty of the views!
Portugal
As well as providing some great weather Portugal has much to offer culturally. There are numerous museums, monuments and places of historical interest to explore. Despite the rich history there is a buzzing nightlife and great shopping too.
Travel
Before making a choice regarding travel, check out the amazing variety of options on Travel.co.uk.
Goa Holidays
Enjoy the warm and sunny climate of Western India. Visit On The Beach for information on Goa holidays.