Memory Management

5 posts, 0 answers
  1. Gord
    Gord avatar
    20 posts
    Member since:
    Jul 2014

    Posted 16 Apr 2015 Link to this post

    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() ?

     

  2. T. Tsonev
    Admin
    T. Tsonev avatar
    2772 posts

    Posted 20 Apr 2015 Link to this post

    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!
     
  3. Kendo UI is VS 2017 Ready
  4. Gord
    Gord avatar
    20 posts
    Member since:
    Jul 2014

    Posted 20 Apr 2015 in reply to T. Tsonev Link to this post

    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.

  5. T. Tsonev
    Admin
    T. Tsonev avatar
    2772 posts

    Posted 22 Apr 2015 Link to this post

    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!
     
  6. Gord
    Gord avatar
    20 posts
    Member since:
    Jul 2014

    Posted 22 Apr 2015 in reply to T. Tsonev Link to this post

    Hello,

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

Back to Top
Kendo UI is VS 2017 Ready