What this article contains
This article starts with Unity's profile component to explore some of the differences in memory usage of unity in the development and formal environments,
and gives the best way to control the memory (I think you already know ...) Prefab), and why.
Articles that need to be read in advance
Before or after reading this article, I suggest reading the following article
The rain is loose.
The Assetbundle of the Unity3d Institute http://www.xuanyusong.com/archives/2405/
The principle of Assetbundle of Unity3d Institute http://www.xuanyusong.com/archives/2373
Wang Wei's
Memory management http://onevcat.com/2012/11/memory-in-unity3d/ in Unity 3D
Stardust (not quite sure if it was the original author ha)
Unity3d a solution that takes up too much memory http://www.cnblogs.com/88999660/archive/2013/03/15/2961663.html
From Ngui's altaspacker.
The cause of the matter is still because I am learning to use the Ngui (just a few days after contacting unity ...), the tutorial looked at it all without a problem when you suddenly found ...
NGUI Create the UI must first create the Altas, then I created a good scatter is put in the project or deleted? does not delete affect performance ?
Google did not find a satisfactory answer, so had to profile it, so the following experiment:
1 · First create an empty scene, run, open profile. Texture (texture) section uses memory 2.5MB
2 • Add a picture and don't make any references on the scene. The image memory expands after the size is 1.5MB, runs and then opens the profile
3 · The miracle thing happened ... The amount of memory consumed by the texture changes directly to 5.8MB
5.8MB-2.5MB = 3.3MB very strange a number, so I also suspect three things
1 · Even if the footage is completely unused, it will eventually be packaged if there is an import in the project
2 · Unity will still load even if the footage is not being used by the current scene (unity starts loading all footage??!)
3 · Unity has a reference to the footage in memory, 3.3MB ~= 1.5mbx2 (??!)
If one of the above three points is true ( all wrong ), then unity will undoubtedly become a waste wood ....
As a matter of three, I began to have an infinite number of inquisitive ....
Kung Fu is not a conscientious, and finally in a piece of a post found a breakthrough
Http://answers.unity3d.com/questions/57909/find-unused-assets-in-project.html
This article makes it clear that unity automatically filters out all unreferenced resources when it is released, and that the entire packaged resource can be viewed via log
Find the log according to the location of the article, and test the above project, play the Android package (Mac log in/users/eran/library/logs/unity/editor.log, Eran for your username)
So the first knot is untied, it seems unity is not so silly ... There is no need to worry about deleting a small map when you use Ngui to make Atlas later.
Now that you know that you can test only on a real machine, you need to repeat the test you just made, but this time it's on the real machine.
1 · First create an empty scene, run, open profile. Texture (texture) section uses memory 153.0KB
It can be noted that the memory footprint is significantly reduced when running on the real machine, and the overhead line is flat, no longer as volatile as the editing environment.
2 • Add a picture and place it on top of the scene
Although not as imagined as the 1.5MB, but since less than 3MB, then Unity3d certainly not be able to leave a copy of the memory of a backup (dram a copy of VRAM, DRAM for processing lostconext when the GPU re-upload).
There's actually a little episode:
In Android above rendering display the use of video memory is 0, this and I understand the 3D rendering principle does not match, has puzzled me for a long time. Did it suddenly come to mind that the phone was the reason for sharing video memory?
Sure enough when I publish the project as a PC version run profile, video memory occupies a number. and memory consumption and I said behind the dynamic culling also has a relationship, said the obvious deposit also occurred swap, this piece and the things said not to elaborate, if the great God to this piece very understanding hope to guide me.
OK continue to say the above mentioned a mouth of the dynamic culling, this is I have no intention to find,
I added a animation to move it around, and when I was testing it, when the picture moved out of the screen, Drawcall would lose 1, which is what unity would automatically remove if the screen didn't see it.
Reduce drawcall, in fact, think about this is a very normal thing, because unity is a complete 3D engine, which is why there is no pixel in unity units is unit, without the width of the screen height, can only adjust the camera's field of view.
In contrast to the previous starling,cocos, although the underlying is also using the GPU for rendering, but his overall engine architecture is based on 2D, it is natural to not be able to complete this automatic culling and memory exchange behavior at the bottom. By contrast, unity is much superior.
To solve this unity puzzle, I got the following two conclusions based on the above experiment.
Conclusion: Even if there are many unused images in the project, as long as they are not placed in a special folder (Resource,streamingassets) and are not referenced by prefab, the final export will not be packaged, but will not occupy video memory, but during the development phase.
Conclusion: Unity automatically rejects objects that move out of the scene to reduce Drawcall
Prefab the best way to manage memory (graphics memory)
My inquisitive behavior is not over here, and since I know how unity loads the footage, when does he unload it?
I have done the following experiment again:
set up two scenes, scenea,sceneb. Loads a texture in Scenea and provides a button to jump to Sceneb .
Click the button to jump to Sceneb,sceneb is an empty scene with nothing to put.
It is expected that when switching to Sceneb time the memory used in Scenea should be released, but the result is disappointing ... Still no change.
Even if I call the GC in the SCENEB is useless (actually seen the GC introduction of friends should know where to tune the GC should be useless)
finally another Google, but this time not as fortunate as the last time there is no harvest, this is the reason I later turned to study prefab. But continue to finish this.
Again, I found that when I set up a Scenec again, the memory in Scenea was released by Scenea->sceneb->scenec at this time. I also sent a question on this issue.
A friend gave him confirmation on the project, unity is really so http://ask.unitymanual.com/question/36097
since the memory that unity automatically manages needs to be eliminated across two scenarios, is there any way we can control it ourselves? The method is to use prefab.
How to create and how to use prefab the two articles of the song have been very clear, I will not repeat the building of wheels.
Conclusion: Unity's own memory recovery needs to pass through two scenarios, and if you use prefab, you can release the video memory when you call Assetbundle.unload (true).
These are some of the experiences I have explored over the past few days and I hope to be of some help to you. If that's not right, ask the great God.
Thank you
Best
Eran
Inquisitive u3d---Spy on Unity's memory management from profile