Code Monkey home page Code Monkey logo

debuggingmemory's Introduction

debuggingmemory's People

Contributors

sawyerlin avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

debuggingmemory's Issues

Feedback (and thanks!)

Hey @gonzaloruizdevilla,

I wanted to thank you once again for putting this (excellent) deck together last year. As you may know it inspired me to flesh out the official memory profiling documentation for DevTools to what we have today & also encouraged me put together an up to date deck on profiling for a last-minute event this week.

I wanted to share some feedback based on the latter about a few things I noticed in case you're giving this talk in the future. Hopefully they'll help avoid some of the issues I ran into:

Timers:

In the current version of the slides, there is definitely a leak caused by the timer but it's so small that it's hardly noticeable. You could attempt to do the same inside a loop (like a few have on StackOverflow) as follows:

for (var i = 0; i < 90000; i++) {
    var buggyObject = {
       callAgain: function() {
         var ref = this;
         var val = setTimeout(function() {
            ref.callAgain(); 
         }, 90000);
       }
    }

    buggyObject.callAgain();
    buggyObject = null;
}

After many rounds of attempting to GC this, the memory consumption remains unchanged.
buggyObject instantiates a setTimeout which calls itself, even if you change buggyObject to
= null. Basically, saying you are done with the object and it can be GC'd. The object
will not be garbage collected because there is still a reference to it in the setTimeout().

Closures:

In the current version, largeStr will attempt to chunk up memory until a is out of scope. I think the messaging around eval might be confusing here too (it's evil, but in this case the wrong tool for the job). That aside, one could rewrite it so that you demonstrate a larger problem - returning a function that passes an argument.

var a = (function () { 
   var smallStr = 'x',
   largeStr = new Array(1000000).join('x'); 

   return function (n) {
        eval('');
        return smallStr; 
   }; 
}());

Memory Leaks:

For the memory leak example with the gallery, it might be useful to comment somewhere what you consider the solution is for users that are looking back at your deck. For example:

  • There is setInterval(move, 2000); in prepareGallery that will be called every click, and there is no clearInterval. A copy of prepareGallery with its property (elements, function definitions etc) will be in memory each click so we should fix that.
  • You could create a reference to setInterval and before re-creating the interval, clear it if it exists. Something like if(x) clearInterval(x); x = setInterval(move, 2000).

Thanks once again for putting this deck together as well as the examples. I hope the docs and our decks on memory profiling GMail and V8 were at least some use for reference.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.