Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

KnockoutJS IE8 performance issues and memory leaks

We build complex enterprise application using KnockoutJS and faced poor performance especially in IE8. Application might take more than 1GB of RAM and never frees memory. During investigation we discovered that KnockoutJS keeps references to the DOM nodes and never deletes it. This can be reproduced using IESieve against any public KnockoutJS example, just watch DOM utilization while playing with example which adds and deletes DOM nodes.

Have anyone faced this problem and has any ideas of how to work this out?

like image 551
Maksym Shpak Avatar asked Nov 05 '12 07:11

Maksym Shpak


2 Answers

We had faced similar issues with knockout JS on IE 8. One of the problem areas was having an observable array (with 500+ elements) and building a UI (imagine a table like or list like structure) with all of those. The only work around that worked for us was to change the view model so that it contains only very few items that could fit on the screen. Also, we had to add handlers for scroll events so that the observable array would keep getting refreshed. And (not too proud of this), we had to add an empty div at the top of the displayed records to give an illusion of the view having scrolled.

like image 99
Ravi Y Avatar answered Oct 16 '22 02:10

Ravi Y


Probably to do with event bindings not being released when their DOM elements get deleted. If it's something thats happening under the hood with knockout, you will have to patch and submit a pull request.

I've had this kind of thing happen a lot with backbonejs too. JavascriptMVC is a bit better for cleaning up after itself.

like image 33
Dom Barker Avatar answered Oct 16 '22 04:10

Dom Barker