title: AssetBundles on iOS: Memory always increases, causing crash
body: <p>We have our asset bundles stored on an Amazon S3 bucket.  When the game starts, it determines which bundles it needs to download new versions of, using WWW.LoadFromCacheOrDownload.</p>
  
  <p>The problem we're running into is the memory iOS reports it has allocated for our app keeps increasing, however the memory Unity reports it's using (through the profiler) always stays the same.  We have enough bundles that by the time it has finished downloading everything we need, it has invariably received a memory warning from iOS, and we are shutdown due to memory pressure shortly after.</p>
  
  <p>Common solutions we have in place already: Unloading the assetbundle after the WWW is finished, using assetBundle.unload(), calling Resources.UnloadUnusedAssets(), and calling Dispose() on the WWW.  None of it is solving the problem.</p>
  
  <p>Code follows:</p>
  
  <pre><code>    private IEnumerator DownloadBundle(DownloadQueueEntry entry, DownloadFinishedCallback callback)
      {
          while (!entry.finished)
          {
              // grab bundle off S3
              string url = string.Format(BUNDLE_URL_FORMAT, entry.directory, entry.assetName);
  
              WWW www = WWW.LoadFromCacheOrDownload(url, entry.version);
  
              yield return www;
  
              if (string.IsNullOrEmpty(www.error))
              {
                  Debug.Log("[BundleDownloader] Download Completed " + entry.assetName);
  
                  entry.finished = true;
                  entry.downloading = false;
                  www.assetBundle.Unload (true);
                  Resources.UnloadUnusedAssets ();
              }
              else
              {
                  // usually timed out resolving host, just try again for now
                  Debug.LogError("[BundleDownloader] Download failed: " + url + " Error: " + www.error);
              }
  
              www.Dispose();
              www = null;
          }
          if(callback != null)
          {
              callback ();
          }
  
      }
  </code></pre>
  
  <p>--edit--</p>
  
  <p>A screenshot showing the increasing memory usage is at the link below.  Memory usage proceeds like that until it has chewed up around 150MB.  This is all in an scene that only has a GameObject for init scripts in it (no art or anything).</p>
  
  <p><a href="https://www.dropbox.com/s/3b6skexz6xhug5g/Screenshot%202014-03-28%2014.54.26.png" rel="nofollow">https://www.dropbox.com/s/3b6skexz6xhug5g/Screenshot%202014-03-28%2014.54.26.png</a></p>