Skip to content
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

cache causes Detached Node memory leaks #115

Closed
wshaver opened this issue Dec 12, 2013 · 4 comments
Closed

cache causes Detached Node memory leaks #115

wshaver opened this issue Dec 12, 2013 · 4 comments

Comments

@wshaver
Copy link

wshaver commented Dec 12, 2013

After a day trying to figure out why I had so many detached elements in my page, I tracked it down to ImagesLoaded, specifically the cache. Because the cache keeps dom node references, it causes potentially hundreds of detached nodes on a dynamic page.

detached

I'm looking at the cache and it contains dom elements that I no longer have on the page.

cache not there

If I comment out the cache and do another profile, there are no detached dom nodes from the same set of actions.

This is somewhat related to #103 but that would force the user to manually clear the cache every time the page changes. Can we do it without retaining a reference to the DOM element?

@wshaver
Copy link
Author

wshaver commented Dec 12, 2013

I've done a clunky work-around on my project that may help someone who finds this issue:

        var onImagesLoaded = function($el, callback){
            var ld = imagesLoaded($el);
            ld.off('always').on('always', function(){
                callback.apply(view, arguments, ld);
                _.each(ld.images, function(loadingImage, index){
                    loadingImage.img = {src:loadingImage.img.src};
                });
                ld.images = [];
                ld.elements = null;
                ld._events = null;
            });
            return ld;
        };

desandro added a commit that referenced this issue Dec 14, 2013
@desandro
Copy link
Owner

Thanks for digging into this! This is not good! 🐐

I've pushed an update that removes reference to any elements in cache. This should resolve it. 👯

Can I ask you to try out and verify?

@wshaver
Copy link
Author

wshaver commented Dec 26, 2013

I've ended up moving away from your plugin and just manually checking the images that I needed to wait for loading on. I don't have an easy way of checking. Thanks for the reply and for open sourcing your project.

@desandro
Copy link
Owner

Closing as fixed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants