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
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

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.
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

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