Proper way to close project and delete Display component

Jan 22, 2013 at 7:55 AM
Edited Jan 22, 2013 at 8:03 AM

Hi,

In my application, when user selects menu item "Close project", I perform the following steps:

internal void DeleteDisplay()
{
    this.project1.Close();
    this.project1.RemoveAllLibraries();

    _display.ShapesInserted -= display_ShapesInserted;
    _display.ShapesRemoved -= display_ShapesRemoved;
    _display.ShapesSelected -= display_ShapesSelected;

    _display.Clear();
    _display.Dispose();
    _display = null;
}

However, I think that not all necessary steps are done here - because if I close my application right after that (by closing its startup form - the one where _display component lived), the following things happen (this is a fragment of the call stack):

(my code goes from here)
Dataweb.NShape.dll!Dataweb.NShape.Advanced.ShapeBase.Dispose() Line 51 + 0x5a bytes	C#
Dataweb.NShape.dll!Dataweb.NShape.Shape.Finalize() Line 39 + 0xb bytes	C#
[External Code]

This means that some shape is still "alive"!

What am I doing wrong?

[UPDATE] next line in the call stack - substituted with "(my code goes from here)" - is the ShapeBase.Disconnect() method override in one of my custom shapes. This method crashes because it calls Repository.GetModelObjects() - and Repository is already closed.

Coordinator
Jan 23, 2013 at 9:03 AM

Difficult to say without knowing what else happens in the application. The code of this method is ok but I think this might have something to do with model objects attached to some shapes:
Each model object stores a reference to every shape it is attached to. So if the model objects are not released with the shapes, the garbage collector cannt free them.

Perhaps you can extract a demo from your application that shows the problem. This would be handy to locate the problem.

Jan 23, 2013 at 9:28 AM
KurtHolzinger wrote:

So if the model objects are not released with the shapes, the garbage collector cannt free them.

Thank you for the answer.

OK, I'll investigate this possibility.

Not sure I can extract a small demo :(