Thanks for the insight. I solved part of the problem by changing how
MochiKit.Base.bind stores the bound object (im_self); instead of
returning a function with the bound object as a direct property of the
function, it stores a numeric index to a table of objects instead.
When binding, if your target object has already been bound before, bind
() just reuses the existing index. It's significantly reduced the
amount of memory being used, although long-term usage of the app still
builds a large table of objects which needs pruned from time to time.
Our app has a state manager built in so I use it to prune the bound
objects list of things that got set up in a given state, upon exiting
that state.

Anyways, here's the updated MochiKit.Base.bind() if anybody is
interested:

          window.onunload = function () {

            delete MochiKit.Base.bindings;
            delete MochiKit.Base.bound_objects;

          };

          MochiKit.Base.bindings      = [];
          MochiKit.Base.bound_objects = [];

          /** @id MochiKit.Base.bind */
          MochiKit.Base.bind = function (func, self/* args... */) {
              if (typeof(func) == "string") {
                  func = self[func];
              }
              var im_func = func.im_func;
              var im_preargs = func.im_preargs;
              var im_self = func.im_self;
              var m = MochiKit.Base;
              if (typeof(func) == "function" && typeof(func.apply) ==
"undefined") {
                  // this is for cases where JavaScript sucks ass and
gives you a
                  // really dumb built-in function like alert() that
doesn't have
                  // an apply
                  func = m._wrapDumbFunction(func);
              }
              if (typeof(im_func) != 'function') {
                  im_func = func;
              }
              if (typeof(self) != 'undefined') {
                  im_self = self;
              }

              im_self_index = null;

              for (var i = 0; i < MochiKit.Base.bound_objects.length; i
++) {

                if (MochiKit.Base.bound_objects[i] === im_self) {

                  im_self_index = i;

                } // end if

              } // end for

              if (im_self_index == null) {

                MochiKit.Base.bound_objects.push(im_self);

                im_self_index = MochiKit.Base.bound_objects.length -
1;

              } // end if

              im_self = MochiKit.Base.bound_objects[im_self_index];

              if (typeof(im_preargs) == 'undefined') {
                  im_preargs = [];
              } else  {
                  im_preargs = im_preargs.slice();
              }
              m.extend(im_preargs, arguments, 2);
              var newfunc = function () {
                  var args = arguments;
                  var me = arguments.callee;
                  if (MochiKit.Base.bindings
[me.index].im_preargs.length > 0) {
                      args = m.concat(MochiKit.Base.bindings
[me.index].im_preargs, args);
                  }
                  var self = MochiKit.Base.bindings[me.index].im_self;
                  if (!self) {
                      self = this;
                  }
                  return MochiKit.Base.bindings[me.index].im_func.apply
(self, args);
              };

              newfunc.index = MochiKit.Base.bindings.length;

              MochiKit.Base.bindings.push({"im_self"    : im_self,
                                           "im_func"    : im_func,
                                           "im_preargs" :
im_preargs});

              return newfunc;
          };
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"MochiKit" group.
To post to this group, send email to mochikit@googlegroups.com
To unsubscribe from this group, send email to 
mochikit+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/mochikit?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to