Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dojo Garbage Collection/Resource Freeing Techniques?

Tags:

dojo

I've recently created what I thought was a page-based application which is now being used embedded as a control. The 'control' needs to unload/reload multiple times. This is causing problems do to subscriptions and dijit controls that were not destroyed. I've worked out the necessary disconnect, registry.destroy logic but it's tedious. Are there any best-practices for making a collection of controls destroy-able?

Here's sample code showing what can be done with basic logic: http://pastebin.com/bUUBUMP9

I'm asking if a framework exists analogous to an AppDomain where anything created in that context can be cleaned up. Similar to embedding the control in an IFRAME...but not.

like image 429
Corey Alix Avatar asked Oct 07 '22 23:10

Corey Alix


1 Answers

I can see two practices that will make your life easier:

  1. Dijit widgets extend dijit/_WidgetBase and therefore a widget provides (dis)connect and (un)subscribe methods. You should use them instead of general purpose aspect.connect() and topic.subscribe() when wiring widgets, because this way the widget disconnects and unsubscribes automatically when being destroyed, so you do not have to.

  2. Organize your widgets via dijit/layout, e.g. use dijit/layout/ContentPane instead of placing widgets just into the DOM, because this way you'll need to call destroyRecursive() just on the ContentPane and it will properly destroy all its children. Nest containers according to your needs to achieve proper granularity and visual appeal (it's the same concept as Java's JPanel).

Applying the aforementioned principles you might only need to call destroyRecursive() on the container highest in the hierarchy to destroy dijits.

like image 60
phusick Avatar answered Oct 12 '22 12:10

phusick