1

I am using Unity AssetBundles for async loading. On iOS this seems to cause a memory leak. Every time I load a new bundle it adds on to the used memory but never seems to release the previous memory even though the unload function and destroy are called. I am not using WWW on iOS because it didn't seem necessary on Unity 5.6.7. The loading works just fine, just an issue with unloading.

I have gone through and compressed all the assets for iOS so that I could get further along in the game. It will still eventually crash on me because it runs out of memory. If it was actually unloading assets it should never use enough memory to crash.

Here is what my UnloadBundle function looks like:

public void UnloadBundle(string bundleName)
{
  if(!m_bundles.ContainsKey(bundleName)) return;

  Hashtable bundle = (Hashtable)m_bundles[bundleName];
  if (bundle.ContainsKey("asset"))
  {
    AssetBundle assetBundle = (AssetBundle)bundle["asset"];
    assetBundle.Unload(true);
    Destroy(assetBundle);
  }

  Resources.UnloadUnusedAssets();

  m_bundles.Remove(bundleName);
}

It should unload the bundle and remove the assets from memory when UnloadBundle("bundlename"); is called. Instead it doesn't free the memory and it continues to climb. The game starts with ~1GB of memory in use and slowly climbs until it gets to ~1.4GB and crashes on iPhone 7.

2
  • Has anyone else seen this issue or know how to fix it? I am at a loss right now. I am trying to think of other ways around this issue. My next attempt will be to force iOS to use the WWW class and see if that will work.. Any other options?
    – cvolpe
    Apr 10, 2019 at 17:24
  • When trying to use WWW on iOS I get the error code -1002 and the connection terminates. developer.apple.com/documentation/foundation/… So that doesn't seem to be an option either.
    – cvolpe
    Apr 11, 2019 at 18:45

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.