View Single Post

  #4 (permalink)  
Old 01-21-2008
Wilfried Wilfried is offline
Senior Member
Black Belt
 
Join Date: Nov 2004
Posts: 2,112
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;
    }
}
Reply With Quote