1 Reply Latest reply on Nov 11, 2013 8:47 PM by Michael J.A. Smith

    Memory allocation : "Closure" what's inside ?


      Does anybody know what are the allocations reported by scout as Closure [type.method <static> (packageName)] ?


      Same question for allocations under "Method closure"




      PS : Btw scout is a great tool, just missing the heap dump analysis

        • 1. Re: Memory allocation : "Closure" what's inside ?
          Michael J.A. Smith Adobe Employee

          A closure is an object representing a function, and its surrounding environment. It takes up memory, because you have to store a reference to any objects external to the function, that are used by the function. For example (in pseudo-syntax):


          var x;

          function y() {

               ... uses x ...



          If you pass the function y() around (e.g. by passing it into a function like addEventListener), the Flash Player has to keep "encapsulate" the environment of f(), so that when it evalues f, it knows what x is referring to. There's a much more detailed explanation here: http://en.wikipedia.org/wiki/Closure_%28computer_science%29


          Typically, a single closure won't take up much memory (although it can prevent other objects from being GCed, by keeping a reference to them). Of course, if you create lots of closures then this memory will add up, but I'd be more concerned about the objects that they're referencing, rather than the closures themselves.