-
Notifications
You must be signed in to change notification settings - Fork 422
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Memory leak in CanJS template/model #1393
Comments
Thanks for posting this.
Can you simplify it a bit more? It's probably possible to create this situation without can.Model or can.fixture. I'm asking because I can't follow the code immediately. I would have to setup this test, which would take some time, and really dive in. If I can follow the code, it's possible I can immediately spot the problem and advise on a fix. Thanks! |
Does this happen stache mustache? (edit stache for mustache) |
I've set up a fiddle. Not sure it is confirming the issue. http://jsfiddle.net/tarabyte/8g0qv4xj/ |
@justinbmeyer Note sure, I haven't tried with stache yet. @Tarabyte On my machine, the script I provided only leaks when you click on the 'Start test (with leak)' button. When checking for memory leaks, I tend to check in complete isolation in a fresh tab - I'm not sure how jsfiddle interacts with all this code - It might skew results... I also noticed that jsfiddle runs the code in an iframe which can affect things too - For example, you will find that deleting the iframe cleans up all memory leaks (because iframe memory is sandboxed). |
@justinbmeyer I will try to reproduce it using a simple Observe instead of the Model + Fixture combination - It might still leak. Ultimately, something appears to be holding on to references of the data. When I was debugging a while ago, I think I saw something about a _cache property somewhere in 'can' and I remember thinking that this could be the cause... Does that ring a bell? |
Yes, the model layer keeps instances, but only while they are bound. Clearing the page should clean them up. Sent from my iPhone
|
@jondubois I'm going to look into this Friday. Anyway we can chat about it sometime on Friday? |
@jondubois I can confirm there is a leak in Mustache, but not in stache. |
@justinbmeyer Thanks for looking into this. We will try to migrate our templates to stache. |
When passing observables obtained from can.Model.findAll() or can.Model.find() into a can.view.mustache template generator, it appears to leak memory. The leak goes away when you call myobservable.attr() instead of passing the myobservable object directly to the template generator function. It doesn't matter whether the data comes from a real AJAX call or is provided by a fixture.
Here is a simple test to reproduce the issue (one button causes memory to leak, and the other doesn't - It just rerenders a template many times):
Note that you need to replace the all dependencies with their appropriate paths on your system.
To check memory consumption in Chrome, use the profiles tab of the developer console and take a memory snapshot before and after each test.
The text was updated successfully, but these errors were encountered: