Howdy Unity gurus!!!
I get out of memory errors now and then just before loading scene "y" from secene "x". Scene"x" is moderate size, not tiny. Scene "y" only has two objects. One with a 1024 texture.
I'm trying the following:
just before loading scene"y" but I'm not using any resource bundles. Would this have any effect? I'm assuming it would dump some memory.
Thx for any tips in advance on this issue.
asked Jan 25 '12 at 04:37 PM
You can profile your memory usage using Instruments through XCode. Simply select Product > Profile from the menu bar, which will compile your app, put it on the device, and automatically open up Instruments (using XCode4, might be the same in XCode3). If you then select "Activity Monitor," you'll get a lot of data on the amount of memory you are using. Depending on your testing device, the acceptable amount of RAM varies.
iPhone3 (128MB total RAM): less than 40MB
iPad1 or iPhone3GS (256MB total RAM): less than 80MB
iPhone4, iPhone4S, iPad2 (512MB total RAM): less than 160MB
Another thing you might want to do is watch your XCode log and see if you are receiving memory warnings. Memory warnings are a pretty good indicator that you are using too much memory and the OS might shut you down.
Then, I've found the following code pretty useful to see everything that is loaded in memory at a given time. It will slow down your build a little bit because it uses UnityGUI, so use it for debugging only, not in production builds:
Finally, Resources.UnloadUnusedAssets() will only work if the asset is truly unused - that is, if there is no remaining script reference to the asset. If any Monobehavior is holding a reference, or if you have a link to a prefab that contains the asset, it will probably not be unloaded as a result of calling this. It is tricky to manage sometimes.
Hope this helps, and good luck!
answered Jan 25 '12 at 09:39 PM