Skip to content
This repository was archived by the owner on Feb 2, 2025. It is now read-only.

Angular Way Temporary Memory Leak with Datatables 1.10.x #319

Closed
coverbeckApigee opened this issue May 19, 2015 · 5 comments
Closed

Angular Way Temporary Memory Leak with Datatables 1.10.x #319

coverbeckApigee opened this issue May 19, 2015 · 5 comments
Labels

Comments

@coverbeckApigee
Copy link
Contributor

I have an "Angular way" angular-datatables, with an ng-repeat. The collection I iterate over in the ng-repeat is refreshed every 20 seconds, via an Ajax call.

Several of the tds in the table have a directive for HighCharts sparklines. The directive has a scope.$on('$destroy',...) where it cleans up. When I leave the page, the $destroy fires for every instance of the directive and all is good.

But when I stay on the page, new directives are compiled each time as a new set of rows are displayed. The existing rows with the compiled directives get detached, but are still around, as far as I can tell. Eventually the page starts getting sluggish and unresponsive as the objects keep accumulating, with their references to HighCharts.

I have created a Plunker to demonstrate the problem with all directives not getting destroyed. You can see in the Plunker that some of the directives are destroyed, but not all of them.

The leakage only happens with 1.10 datatables; it doesn't happen with 1.9. You can comment/uncomment the lines in index.html in the Plunker to specify which version of datatables to include and see the different behavior.

Thanks,

Charles

@coverbeckApigee coverbeckApigee changed the title Angular Way Temporary Memory Leak Angular Way Temporary Memory Leak with Datatables 1.10.x May 20, 2015
@l-lin
Copy link
Owner

l-lin commented May 20, 2015

Mmh interesting. The ngDestroy was just the copy of DataTable destroy function.
Don't really know what the fix should be though... 😞

@coverbeckApigee
Copy link
Contributor Author

Hi @l-lin ,

I tried this and it seems to fix my problem. I've only tested with "Angular way" and Datatables 1.10.6. What do you think?

....
var _parentScope;
var _childScope; // Added this
....

function _destroyAndCompile() {
    if (_childScope) {
        _childScope.$destroy();
    }
    _oTable.ngDestroy();
    // Re-compile because we lost the angular binding to the existing data
    _childScope = _parentScope.$new();
    _$elem.html(_staticHTML);
    $compile(_$elem.contents())(_childScope);
}

@l-lin
Copy link
Owner

l-lin commented May 22, 2015

Yes, it does seem to work. Can you make a PR?

@coverbeckApigee
Copy link
Contributor Author

Sorry for the delay; I just made a PR.

@l-lin l-lin removed the Help wanted label May 26, 2015
@l-lin
Copy link
Owner

l-lin commented May 26, 2015

Fixed with PR #326.

@l-lin l-lin closed this as completed May 26, 2015
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

2 participants