memory keeps growing after many scene load additive/destroy cycles

hi,

my company does a big game, so we use loadleveladditiveasync a lot.
our project has a few scenes, that have to be loaded all the time, for example mouse managements,…
if the player switches to another part of the game, we do a destroy some scenes and do load additive with some new ones.
this cylce can repeat it self very often, if the player switches between the game parts very often.
we had a strange effect after loading a scene, it crashed after switching to it 3 or more times with the method described above.
after that we discovered it happens almost always with other scenes too if you do the cycle enough times.

try the following code: (memory will increase, but it should not, or should it???)

void Start () {
	StartCoroutine("mytest");
}
	
IEnumerator mytest()
{
	AssetBundle anAssetBundle = null;
			
	for (int i=0;i<100;i++)
	{
		WWW aWWW = new WWW("file://......");
		yield return aWWW;
		anAssetBundle = aWWW.assetBundle;

		AsyncOperation anOperation = Application.LoadLevelAdditiveAsync(aScene);
		anAssetBundle.Unload(false);

		yield return anOperation;
		print(i);
		yield return new WaitForSeconds(2f);
		
		GameObject aGameObject = GameObject.Find("scene root name");
		GameObject.Destroy(aGameObject);

		yield return new WaitForSeconds(1f);
	}
}

but if we do www only one time, it memory keeps almost constant:

void Start () {
	StartCoroutine("mytest");
}
	
IEnumerator mytest()
{
	AssetBundle anAssetBundle = null;

	WWW aWWW = new WWW("file://......");
	yield return aWWW;
	anAssetBundle = aWWW.assetBundle;
			
	for (int i=0;i<100;i++)
	{
		AsyncOperation anOperation = Application.LoadLevelAdditiveAsync(aScene);
		yield return anOperation;
		print(i);
		yield return new WaitForSeconds(2f);
		
		GameObject aGameObject = GameObject.Find("scene root name");
		GameObject.Destroy(aGameObject);

		yield return new WaitForSeconds(1f);
	}
}

but we do not want to keep currently unneeded assetbundles in memory. what can/should we do?

Some asset types (most notable textures) use additional memory beyond whatever is used by object instances. Without knowing what is going on in your game, it is hard to say if this might be what is causing your problem. However, you might find that calling Resources.UnloadUnusedAssets after removing a section of scene will fix the memory usage problem.