Skip to content

Memory leak - detached dom tree #523

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

Closed
trompx opened this issue Apr 27, 2015 · 4 comments
Closed

Memory leak - detached dom tree #523

trompx opened this issue Apr 27, 2015 · 4 comments

Comments

@trompx
Copy link

trompx commented Apr 27, 2015

Hello,

I don't know if this bug is related to my code but I had a memory leak issue as you can see on the following image :

memory-leak-pjax

While looking for potential similar isuues, I stumble upon this "fixes" which solved my memory leak problem : #465 and related to #453

For the time being I will stick with this solution as the memory leak was really annoying and will let you know if using the html approach creates unwanted effects.

Let me know if you think about something to get rid of this problem using cloneContents.

@mislav
Copy link
Collaborator

mislav commented Apr 27, 2015

At what magnitude does the leak affect you? How much is actually "leaking"?

This isn't so much a leak as it is keeping DOM trees in memory by design so that they can be restored. You can experiment with applying the aforementioned patch and storing them as strings, of course. You can set maxCacheLength: 0 to disable the popstate cache altogether.

But I'm open to explore alternative caching strategies that are more efficient.

@trompx
Copy link
Author

trompx commented Apr 29, 2015

It was affecting me pretty badly. On each page load I hade around 5000 entries added, so on the chrome timeline, my memory Nodes count was exploding very quickly.

With the .html() way of caching, I was able to reduce that to 400 entries (not due to pjax but to some closure on a scroll event).

It is kind of hard to benchmark the impact, I tried to monitor the ram increase in the chrome task manager, it looks like it helped a bit but could not say precisely how much, I could still try to investigate a bit more if it may helps.

@mislav
Copy link
Collaborator

mislav commented May 12, 2015

Please let us know when you find some absolute values. 5000 entries added might be a lot, or it might not be a lot if every entry is 1 byte. So, dealing with absolute values in megabytes is crucial to understanding just how severe the memory leak is.

Also, please be aware that this is not a memory leak per se, but that pjax's internal cache is by design. If your pages are huge, you can disable the memory cache with maxCacheLength: 0 and avoid this issue altogether.

@mislav
Copy link
Collaborator

mislav commented May 23, 2017

Closing because some extra memory usage is expected with pjax due to its in-memory cache. This can be reduced with maxCacheLength option. Otherwise, there seem to be no other reports of actual memory leaks with pjax (leaks that accummulate endlessly over time and grind the page to a halt).

@mislav mislav closed this as completed May 23, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants