I have a problem when loading the assetBundle by myself.i found the memory can not be free,my unity version is 5.1.2,the platform is android
The code is very simple.What the code do is just to load and unload 100 assetsbundles that has no dependce with each other.All the assetbundles in the memory will cost 115M.When i just open the app with doing nothing,the app’s total memory is 30M.When i use function1 to load and unload 100 assetbundles ,the memroy will back to be 30M,but when i use funtion 2 which is exactly will be used in my real project,the memroy will growth to be 70M
function1:
//-------------------------------------------------------------before 30M
public void LoadAndUnload()
{
foreach (var file in files)
{
byte[] bytes = LoadFromCacheDirect(file);
AssetBundle assetBundle = AssetBundle.CreateFromMemoryImmediate(bytes);
assetBundle.Unload(false);
}
//Resources.UnloadUnusedAssets(); do or do not ,there is no use
GC.Collect();
}
//---------------------------------------------------------------after 30M
in the function1 ,i call the “assetBundle.Unload” function when the assetBundle just be created. After this function,the assetbundle memory will be all free.
function2:
//-------------------------------------------------------------before 30M
public void LoadAllAndUnload()
{
foreach (var file in files)
{
byte[] bytes = LoadFromCacheDirect(file);
AssetBundle assetBundle = AssetBundle.CreateFromMemoryImmediate(bytes);
abs.Add(file, assetBundle);
}
//-------------------------------------------------------------middle 115M
foreach (var rr in abs)
{
var assetBundle = rr.Value;
if (assetBundle != null)
{
assetBundle.Unload(false);
}
}
//Resources.UnloadUnusedAssets(); do or do not ,there is no use
GC.Collect();
}
//-------------------------------------------------------------after 70M
in the function2 ,I stored the assetbundle in the dictionary “abs” when it just be created.when all the 100 assetbundles be stored,i iteartor the dictionary and call the "assetBundle.Unload"function one by one.but only part of the memory will be free after function2.
I have tried many ways but still can’t found how to free the memory.the profiler shows there is no webStreams ,no serialized file , no asset in the memory after call funtion2,I’am lost!
Please help~