title: Swift: clear array in iteration function
body: <p>I want to use this iteration function to check a array, and store the result with new array, and then check the new array again and again...however I don't know how to clear the the old useless arrays so that the memory can be released. </p>
  
  <pre><code>func checkEnvironment(environment: [MGLPolygon], seed: MGLPolygon) -&gt; [MGLPolygon]?{
      var newEnv: [MGLPolygon]?
      var alien: MGLPolygon?
      var check = false
      for i in 0..&lt;environment.count{
          if detectIntersect(poly1: seed, poly2: environment[i]) &amp;&amp; check == false{
              check = true
              alien = seed
              newEnv?.append(alien!)
          }else{
              newEnv?.append(environment[i])
          }
      }
  
      if check == false{
          // error occurs on here  
          environment.removeAll()
          return newEnv!
      }else{
          checkEnvironment(environment: newEnv!, seed: alien!)
      }
      return nil
  }
  </code></pre>
  
  <p>in the code</p>
  
  <pre><code>environment.removeAll() 
  </code></pre>
  
  <p>gets a error that says environment is a let static so I can't change it. My question is how do I release the memory form those array? 
  Any help would be appreciate.</p>