jQWidgets Forums

jQuery UI Widgets Forums Grid Memory leak using jqxgrid in an iframe

This topic contains 16 replies, has 7 voices, and was last updated by  dhroth 6 years, 7 months ago.

Viewing 2 posts - 16 through 17 (of 17 total)
  • Author

  • andrea
    Participant

    Hi Dave Roth,
    could you provide a small example of your wrapper functions with the workaround solution ?
    I also agree that the clean up should be done by the widgets components directly when they are destroyed.

    I have a similar memory leak problem with the jqxgrid (5.6.0) in Angular 5.2.9 in a single page application.
    Basically if the grid contains at least one column with ‘createwidget’ defined (even if the function is empty) then the component is not removed from the browser memory when it is destroyed.
    So the memory usage keeps growing when switching from one page to another.

    Thanks and Regards
    Andrea

    Memory leak using jqxgrid in an iframe #101917

    dhroth
    Participant

    Sorry, I just saw this now. If it is too late for your use, I’ll post the example for the jqxGrid.js _addHandlers function anyway for others if needed.

    First we defined a global JS variable that will hold a reference to the jqxGrid _addHandlers function. We null this variable when no longer needed.
    var _jqxGrid_addHandlers_Func = null;

    During our startup process, we make that assignment to save the reference to the function.
    _jqxGrid_addHandlers_Func = $.jqx._jqxGrid.prototype._addHandlers;

    Then we use jQuery to extend the jqxGrid object and override the _addHandlers function. When the _addHandlers function is called, we temporarily make the addEventListener and attachEvent methods on the window.top.document be an empty function that does nothing and then call the saved reference to the real _addHandlers jqxGrid function. We then put back the standard addEventListener and attachEvent methods on window.top.document.

    We lose the jqxGrid handling of the mouseup when the user clicks in the grid and drags the mouse outside the grid before releasing the mouse button. We were willing to accept that in order to get rid of the memory leaks and browser crashes.

    
    $.extend($.jqx._jqxGrid.prototype, {
        _addHandlers: function() {
            if (window.top != null && window.top != window.self && window.top.document) {
                if (window.top.document.addEventListener) {
                    windowTopAddAttachEventListener = window.top.document.addEventListener;
                    window.top.document.addEventListener = function(eventType, eventHandler, useCapture) {
                        return;  
                    };
                } else if (window.top.document.attachEvent) {
                    windowTopAddAttachEventListener = window.top.document.attachEvent;
                    window.top.document.attachEvent = function(eventType, eventHandler) {
                        return;  
                    };
                }
            }
            this.that = this;
            _jqxGrid_addHandlers_Func.call(this);
            if (window.top != null && window.top != window.self && window.top.document) {
                if (window.top.document.addEventListener) {
                    window.top.document.addEventListener = windowTopAddAttachEventListener;
                } else if (window.top.document.attachEvent) {
                    window.top.document.attachEvent = windowTopAddAttachEventListener;
                }
            }
            windowTopAddAttachEventListener = null;
        }
    });
    
Viewing 2 posts - 16 through 17 (of 17 total)

You must be logged in to reply to this topic.