This is a migrated thread and some comments may be shown as answers.

Memory Management

4 Answers 119 Views
Drawing API
This is a migrated thread and some comments may be shown as answers.
Gord
Top achievements
Rank 1
Gord asked on 16 Apr 2015, 01:23 PM

I just had a quick question regarding memory management with the Drawing API.  There doesn't appear to be any documented "destroy" method for the drawing elements (Group, Path, etc.).  Is it sufficient to call surface.destroy() to properly clear up and remove all drawing content? 

 Also, I noticed that calling surface.destroy() does not appear to remove the markup from the page.  Do I need to manually remove the SVG element from the document with something like $("#container").find("svg").remove() ?

 

4 Answers, 1 is accepted

Sort by
0
T. Tsonev
Telerik team
answered on 20 Apr 2015, 08:09 AM
Hi,

Destroying the surface will surely release all resources. Your shape references, if any, will remain active.
That is, you can construct a scene, draw it on a surface, destroy the surface and then draw it again on another surface.

If you don't need the shapes lying around just drop the references to them.

The destroy operation won't touch the DOM elements. We do this for the rest of the Kendo UI widgets as well.
In this case it might be useful if you want to leave some static graphics on the page, for example.

I hope this helps.

Regards,
T. Tsonev
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
0
Gord
Top achievements
Rank 1
answered on 20 Apr 2015, 01:09 PM

Hello,

Just so I understand this correctly;

In my situation, I have created a view class by extending kendo.Class, and when it initializes, it creates a surface reference and stores it to the view (this.surface =...).  It also creates a root Group object, and attaches all shapes to it for display.  Then it runs "surface.draw" to display the content.

I have a possible workflow where the user may want to completely destroy the surface and re-render it with new data (databinding, changing a model, etc.).  In this situation, to clean up all memory used by this view that I have created, would this be sufficient:

I call "this.surface.destroy()" then "this.surface = null".  Set the stored root group to null ("this.root = null") and then I clear out the HTML by doing:  $("#canvas").unbind(); $("#canvas").innerHTML = ""; $("#canvas").remove();

My biggest concern in this situation is if we have an auto-refresh that redraws this view every x-seconds, I want to avoid any memory leaks.

0
T. Tsonev
Telerik team
answered on 22 Apr 2015, 11:28 AM
Hi,

In your case it might be better to just clear the drawing surface. Then recreate the root group and continue as normal.

Does this make sense?

Regards,
T. Tsonev
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
0
Gord
Top achievements
Rank 1
answered on 22 Apr 2015, 04:11 PM

Hello,

 Cool!  I'll try that out and test the memory usage.

Tags
Drawing API
Asked by
Gord
Top achievements
Rank 1
Answers by
T. Tsonev
Telerik team
Gord
Top achievements
Rank 1
Share this question
or