Uploaded image for project: 'Sling'
  1. Sling
  2. SLING-8574

Memory leak via cached JavaScript factory functions in SlyBindingsValuesProvider



    • Bug
    • Status: Open
    • Critical
    • Resolution: Unresolved
    • Scripting HTL JS Use Provider 1.0.28
    • None
    • Scripting


      While analyzing excessive memory usage in an AEM 6.4 instance I discovered a memory leak transitively introduced via the SlyBindingsValues Provider.

      Here, a configurable list of JavaScripts is run to produce factory functions. These functions are retained in an application-scoped map in order to be injected into the bindings of future script executions.

      Here, the SlyBindingsValuesProvider creates these factory function instances by executing the factory scripts using, amongst others, the current ENGINE-scoped script bindings.

      The resulting compiled JS representations reference a org.mozilla.javascript.NativeCall instance, which is referencing a org.mozilla.javascript.ImporterTopLevel instance. This ImporterTopLevel instance has a slots[] array member who's Slot instances point to org.mozilla.javascript.NativeJavaObject instances representing at least all objects present in the bindings during the factory script execution.

      Thus, a chain of strong references is formed to request-scoped instances. This keeps open dozens to potentially thousands of request-scoped Objects such as Sling Models, requests, resources, resource resolvers and their respective transitive hull, resulting in significant memory consumption.


      I have attached an excerpt of the respective view on the Heap generated using JProfiler. Note that the issue is not specific to the aem.js mentioned therein, but is generally caused by any of the factory scripts.





            Unassigned Unassigned
            o.otto Olaf Otto
            0 Vote for this issue
            1 Start watching this issue