MapPoint Forums

MapForums

Community of VE/MapPoint Users and Developers




base.Dispose() hung the program

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 ...


Go Back   MapPoint Forums > Map Forums > MapPoint 2006/2009 Discussion

Register Blogs FAQ Members List Calendar Search Today's Posts Mark Forums Read



Click here to register

Reply

 

LinkBack (1) Thread Tools Display Modes
  1 links from elsewhere to this Post. Click to view. #1 (permalink)  
Old 01-18-2008
Senior Member
Green Belt
 
Join Date: Jul 2005
Posts: 105
base.Dispose() hung the program

On a window with MapPoint 2004 I found my program hanging and needing to be reboored.

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
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #2 (permalink)  
Old 01-19-2008
Senior Member
Green Belt
 
Join Date: Jul 2005
Posts: 105
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.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #3 (permalink)  
Old 01-19-2008
Senior Member
Green Belt
 
Join Date: Jul 2005
Posts: 105
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 );
}
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #4 (permalink)  
Old 01-21-2008
Senior Member
Black Belt
 
Join Date: Nov 2004
Posts: 2,094
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;
    }
}
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #5 (permalink)  
Old 01-21-2008
Winwaed's Avatar
Mapping-Tools.com
Red Belt
 
Join Date: Feb 2004
Posts: 847
Blog Entries: 7
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
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #6 (permalink)  
Old 01-23-2008
Senior Member
Green Belt
 
Join Date: Jul 2005
Posts: 105
Re: base.Dispose() hung the program

Thanks for the help.

Bob
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #7 (permalink)  
Old 02-11-2008
Senior Member
Green Belt
 
Join Date: Jul 2005
Posts: 105
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;
}
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #8 (permalink)  
Old 02-15-2008
Senior Member
Black Belt
 
Join Date: Nov 2004
Posts: 2,094
Re: base.Dispose() hung the program

Hi,

As far as I know is clearing the route sufficient.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Reply

Tags
basedispose, hung, program


LinkBacks (?)
LinkBack to this Thread: http://www.mapforums.com/base-dispose-hung-program-7019.html

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

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads

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


All times are GMT -5. The time now is 08:04 PM.


Powered by vBulletin® Version 3.7.2
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0
MP2K Magazine
Visitor Map

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.


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52