- Home /
How do I destroy things properly to free up memory? (iOS)
I'm loading AudioClips and Texture2D from Resources a lot.
Do I need to Destroy() them when I no longer need them? Is it the same thing to set the variable holding them to null?
Or how do I make sure everything is destroyed when I no longer need it?
Answer by col000r · Dec 13, 2011 at 09:45 AM
And the correct answer is: You need to call Resources.UnloadUnusedAssets() or assets loaded from resources will stay in memory FOREVER! There should really be a huge red warning-box on all the documentation-pages about Resources stating this! :)
I absolutely agree. I had to be told by Unity's support staff about this in a reply to a bug report before I got it. Unity's memory management is really something that needs to be documented better.
Wow! this helped me amazingly!
i put this in the AppController in applicationDidReceive$$anonymous$$emoryWarning and used a UnitySend$$anonymous$$essage to dealloc memory, saved my app! i used a lot of textures, loaded as WWW that (strangely) never got cleared up
thank you!
i put this in the AppController in applicationDidReceive$$anonymous$$emoryWarning and used a UnitySend$$anonymous$$essage to dealloc memory, saved my app!
Dear vanss2: Please could you post your code?
- (void)applicationDidReceive$$anonymous$$emoryWarning:(UIApplication*)application
{
::printf("WARNING -> applicationDidReceive$$anonymous$$emoryWarning()\n");
UnityLow$$anonymous$$emory();
UnitySend$$anonymous$$essage(<#const char *obj#>, <#const char *method#>, <#const char *msg#>) // <= What exactly did you put here?
}
Sure this is going to rescue my app, too. Thanks alot.
Thanks, looking at xcodes memory when testing the build you can really tell a difference
Answer by Jean-Fabre · Sep 04, 2012 at 08:07 AM
Hi,
Check this Answer because Resources.UnloadUnusedAssets() wasn't really doing the job for me on level loading.
Answer by khross · Jan 25, 2017 at 01:29 PM
Is the correct answer still valid for current version ? (5.5.0f3). Or there is a smarter GC system already implemented ?
Your answer
Follow this Question
Related Questions
IPhone 4 and IPad 2 lost audio on resume 0 Answers
What does Mprotect remapping failed mean and how do I fix it? 1 Answer
Fixing Layout issues for iPad 0 Answers
Error linker IOS / Unity - XcODE 2 Answers