Monday, June 17, 2013

dropping stuff out of a Dojo 1.9 registry

I had been destroying unwanted temporary views in a dojox/app application like so...

function destroyView(view) {
   delete app.views[view];
   id = domMonikerForView + view;
   require(["dojo/dom-construct"], function(domConstruct){
      domConstruct.destroy(id);
   });
}

 
 

...but now I am doing so as seen here in the name of cleaning up the dojo registry first.

function destroyView(view, domNode) {
   delete app.views[view];
   require(["dijit/registry"], function(registry){
      var widgets = registry.findWidgets(domNode);
      _.each(widgets, function(widget) {
         widget.destroyRecursive(true);
      });
   });
   require(["dojo/dom-construct"], function(domConstruct){
      domConstruct.destroy(domNode.id);
   });
}

 
 

The registry keeps a living record of AMD modules which have been brought into state. One of my superiors thought that just dropping the view for a div without cleaning up the registry could open the door to a memory leak as there could be events tied to the views. It's hard to know. I don't know what dojox/app does under the hood to keep views/controllers in state as of yet.

No comments:

Post a Comment