GoView instances kept forever

Hi,

I’ve been fighting memory leaks in my application and it turned out that one of them originates probably in GoDiagram.

I’m keeping an instance of GoDocument in my application. For editing, my application creates a modal form with a GoView control, setting its Document property to my document. So, basically, a new view is created for editing each time and I would expect all objects related to this particular view to be gone when the form is closed.

However, after investigating the problem with .NET Memory Profiler, it turned out that GoLayer (belonging logically to the document) probably caches references to GoView objects that were ever used to display it. Here is the root path to the closed GoView obtained with the profiler:

– namespace — – class —
Northwoods.Go GoLayer.GoLayerCache
Northwoods.Go GoLayer.GoLayerCache[]
System.Collections.Generic List<GoLayer.GoLayerCache>
Northwoods.Go GoLayer
Northwoods.Go GoDocument
GoDiagramLeak Form1

It causes a memory leak, because each time the editor form is opened and closed yet another GoView reference is kept forever (well, while the GoDocument is alive).

Is there any way to “detach” a view from the document or to explicitly clear the cached view? Or maybe I’m doing something wrong? By the way, I’m calling GoView.Dispose() in editor form’s Dispose().

This issue can be reproduced in a simplest application. Form1 has a single button and the code behind is:

public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();

        _document = new GoDocument();

        GoBasicNode node1 = new GoBasicNode();
        // specify position, label and color
        node1.Location = new PointF(100, 100);
        node1.Text = "first";
        node1.Editable = true; 
        node1.Shape.BrushColor = Color.Blue;

        _document.Add(node1);
    }

    private GoDocument _document;

    private void button1_Click(object sender, EventArgs e)
    {
        using (Form2 f2 = new Form2())
        {
            f2.SetDocument(_document);
            f2.ShowDialog();
        }
    }
}</font>

Form2 has just a GoView control and this code:

public partial class Form2 : Form
{
public Form2()
{
InitializeComponent();
}

    public void SetDocument(GoDocument document)
    {
        goView1.Document = document;
    }
}</font>

We’ll take a look…

We’ve confirmed the issue, there will be a fix in 4.1 for this.