4 Replies Latest reply on Feb 12, 2011 11:09 AM by Marc Autret

    [CS4][Win] ScriptUI Window.children Memory Leak?

    Marc Autret Level 4

      Hi people,

       

      I'm fighting against a frustrating memory issue which seems to affect ScriptUI 4.0 (CS4).

       

      Here is a minimalist code to illustrate my point:

       

      // Use a persistent engine
      #targetengine 'myTest'
      
      // Create a minimal Dialog
      var w = new Window('dialog');
      
      // Just 'hit' w.children --does nothing!
      w.children;
      
      // Nullify w
      w = null;          
      
      // Double garbage collection
      $.gc();
      $.gc();
      
      // Count the residual objects/instances
      alert( $.summary() );
      

       

      When I run this script in CS4, I note that $.summary() reports one instance of Window and one instance of Collection, as if these objects were not deallocated after an explicit destruction. Indeed, when I run the script several times, I get an increasing number of Window and Collection instances.

       

      So I suspect that ScriptUI 4.0 causes a kind of circular reference between w (Window) and w.children (Collection) that makes the GC ineffective.

       

      All this does not happen if you just remove the line:

      w.children;

       

      (Moreover, the problem does not occur in CS5.)

       

      Should we conclude that any CS4 script that creates a ScriptUI dialog in a persistent engine and use the Window.children property at any moment is unable to properly release the memory?

       

      Here is an excerpt from the allocation table returned by the (hidden) $.list() function after 5 executions of the script:

       

      Address  L Refs Prop Class      Name
      
      1743d828 L    1    1 Collection Object            referenced by:
      206b2698 L    0    0 Window     Window            children
      
      206b2698 L    0    0 Window     Window           
      20689550      3    0 Function   [toplevel]       
      206b1e80 L    1    1 Collection Object            referenced by:
      2069fc20 L    0    0 Window     Window            children
      
      2069fc20 L    0    0 Window     Window           
      2069f5b8 L    1    1 Collection Object            referenced by:
      206a0cb8 L    0    0 Window     Window            children
      
      206983a0      5    1 Object     Collection        referenced by:
      206970f8      2    2 Function   Collection        prototype
      
      20698308 L    1    1 Collection Object            referenced by:
      206958c0 L    0    0 Window     Window            children
      
      206970f8      2    2 Function   Collection        referenced by:
      206983a0      5    1 Object     Collection        constructor
      173a7b30 L    4    0 global     global           [global] Collection
      
      20696908      5    1 Object     Window            referenced by:
      20696660 L    2    2 Function   Window            prototype
      
      206958c0 L    0    0 Window     Window           
      20696660 L    2    2 Function   Window            referenced by:
      20696908      5    1 Object     Window            constructor
      173a7b30 L    4    0 global     global           [global] Window
      

       

      I am looking after a way to eradicate all traces of these ghost references.

       

      Thank you in advance for any help.

       

      @+

      Marc