Welcome to MapForums!

Register, sign in, or use Facebook Connect above to join in and participate in the forum.

When you are signed in, this message, the ads in this row, and the red-underlined link ads all go away.

Subscribe to receive our newsletter.
Subscribe Unsubscribe
Results 1 to 8 of 8

base.Dispose() hung the program

This is a discussion on base.Dispose() hung the program within the MapPoint Desktop 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 ...

  1. #1
    BobFromBoston is offline Senior Member Green Belt
    Join Date
    Jul 2005
    Posts
    128

    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

  2. #2
    BobFromBoston is offline Senior Member Green Belt
    Join Date
    Jul 2005
    Posts
    128

    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.

  3. #3
    BobFromBoston is offline Senior Member Green Belt
    Join Date
    Jul 2005
    Posts
    128

    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 );
    }

  4. #4
    Wilfried is offline Senior Member Black Belt
    Join Date
    Nov 2004
    Location
    Belgium
    Posts
    2,433

    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;
        }
    }

  5. #5
    Winwaed's Avatar
    Winwaed is offline Mapping-Tools.com Black Belt
    Join Date
    Feb 2004
    Location
    Irving,Texas
    Posts
    1,859
    Blog Entries
    60

    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

  6. #6
    BobFromBoston is offline Senior Member Green Belt
    Join Date
    Jul 2005
    Posts
    128

    Re: base.Dispose() hung the program

    Thanks for the help.

    Bob

  7. #7
    BobFromBoston is offline Senior Member Green Belt
    Join Date
    Jul 2005
    Posts
    128

    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;
    }

  8. #8
    Wilfried is offline Senior Member Black Belt
    Join Date
    Nov 2004
    Location
    Belgium
    Posts
    2,433

    Re: base.Dispose() hung the program

    Hi,

    As far as I know is clearing the route sufficient.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Base Meridian/Township/Range/Section data
    By Anonymous in forum MapPoint Desktop Discussion
    Replies: 2
    Last Post: 10-07-2008, 05:40 PM
  2. Reverse Geocode base on Zip?
    By DotNetAllDay in forum Bing Maps and MapPoint Web Service
    Replies: 0
    Last Post: 10-12-2007, 06:04 PM
  3. MS Access-single data base/multiple Map categories
    By teishin in forum MapPoint Desktop Discussion
    Replies: 1
    Last Post: 01-05-2007, 09:35 AM
  4. Map points base map
    By KevP in forum MapPoint Desktop Discussion
    Replies: 1
    Last Post: 10-18-2005, 06:36 PM
  5. Replies: 0
    Last Post: 12-18-2002, 11:40 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24