title: Spark memory leaks
body: <p>I've been trying to track down memory leaks in our application, and keep finding myself back looking at Spark components as the culprit.</p>
  
  <p>I think I've found the cause, but my understanding of Garbage Collection / mark &amp; sweep is not too hot, so I'd like to verify my findings.</p>
  
  <p>Many classes in Spark use <code>RichEditableText</code> for displaying their text properties (<code>ComboBox</code>,<code>TextInput</code>).  </p>
  
  <p><code>RichEditableText</code> has a local <code>textContainerManager</code> property, and frequently calls <code>compose()</code> on this.</p>
  
  <p>Here's the relevant abridged extract from <code>TextContainerManager</code></p>
  
  <pre><code>// Line 282 - 292:
      static private var stringFactoryDictionary:Dictionary = new Dictionary(true);
      static private function inputManagerStringFactory(config:IConfiguration):StringTextLineFactory
      {
          var factory:StringTextLineFactory = stringFactoryDictionary[config];
          if (factory == null)
          {
              factory = new StringTextLineFactory(config);
              stringFactoryDictionary[config] = factory;
          }
          return factory;
      }
  // Line 1204:
  public function compose() {
      // Line 1238:
      var inputManagerFactory:TextLineFactoryBase = (_sourceState == SOURCE_STRING) ? inputManagerStringFactory(_config) : _inputManagerTextFlowFactory;
      // Line 1242:
      inputManagerFactory.swfContext = Configuration.playerEnablesArgoFeatures ? this : _swfContext;
  }
  </code></pre>
  
  <p>Line 1242 is the crucial line here, as it gives the static dictionary a reference to our component.</p>
  
  <p>(Note - I've checked this with the debugger to confirm which branch of the ternary gets executed.)    This would prevent the instance from ever being garbage collected.  </p>
  
  <p>Eg:  Static dictionary has a value with a reference to the instance -- instance cannot be GC'd.</p>
  
  <p>In turn, this would prevent any other instances which have a reference to the instance of <code>TextContainerManager</code> from being GC'd also.</p>
  
  <p>While this theory certainly matches what I'm seeing in our app, I can't beleive that there really is a memory leak in such a low-level spark component.</p>
  
  <p>Could someone please shed some light on this?</p>
  
  <p>BTW - I've opened a defect on bugs.adobe.com to track this issue, should it prove to be a genuine bug:
  <a href="https://bugs.adobe.com/jira/browse/SDK-29531" rel="nofollow">https://bugs.adobe.com/jira/browse/SDK-29531</a></p>