Profile Picture

Proper way to remove shapes from DIagram? Memory leak?

Posted By Jason Irby 4 Years Ago
Author
Message
Jason Irby
Problem Posted 4 Years Ago
View Quick Profile
Forum Member

Forum Member (39 reputation)Forum Member (39 reputation)Forum Member (39 reputation)Forum Member (39 reputation)Forum Member (39 reputation)Forum Member (39 reputation)Forum Member (39 reputation)Forum Member (39 reputation)Forum Member (39 reputation)

Group: Forum Members
Last Active: Last Month
Posts: 54, Visits: 60

1.  What is the proper way to remove a NShape or NGroup from a NDrawingDocument?
2.  What is the proper way to clear out all shapes from  a NDrawingDocument?

I have been using:
mydocument.ActiveLayer.RemoveChild(aShape);
mydocument.ActiveLayer.RemoveAllChildren();

My problem is that in testing with .Net Memory Profiler, I am seeing the number of NGroups continue to grow even though I thought I had removed them.  

They seem to be held by the document.EventSinkService in a field call "|1|||I||" what ever the heck that is.

AM I doing it right?

Thanks in advance.

Jason




Nevron Support
Posted 4 Years Ago
View Quick Profile
Supreme Being

Supreme Being (3,954 reputation)Supreme Being (3,954 reputation)Supreme Being (3,954 reputation)Supreme Being (3,954 reputation)Supreme Being (3,954 reputation)Supreme Being (3,954 reputation)Supreme Being (3,954 reputation)Supreme Being (3,954 reputation)Supreme Being (3,954 reputation)

Group: Forum Members
Last Active: 13 hours ago
Posts: 2,888, Visits: 3,074
Hi Jason,

Yes you are removing the shapes correctly. If the shapes are however connected you may consider the NBatchDelete to perform the removal. For an example see the following topic:
Diagram for .NET > User's Guide > Document Object Model > Batches

The memory leak may occur if you locally subscribe for events of the shapes for example like that:
shape.BoundsChanged += somedelegate;

Because we wanted to optimize the memory footprint and performance of shapes, the shapes do not have local events declared on them, but rather use the EventSinkService to record "per node" events. This helps us for example temporary "block" all events when performance is required - for example during BeginUpdate()/EndUpdate() of the drawing.

You are right however that this can generate a memory leak. To detach a shape from all events for which you have locally subscribed you can use the following code:

drawingdocument.EventSinkService.RemoveAllNodeEventListeners(shape);




Best Regards,
Nevron Support Team





Similar Topics


Reading This Topic