- Home /
Why is Unity for iOS causing Memory Leaks w/o WWW class being called?
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.
When trying to use WWW on iOS I get the error code -1002 and the connection terminates.
So that doesn't seem to be an option either.
Didn't get any responses from my StackOverflow post:
... so I thought I would try here.