As defined on Memorymanagement.org:
"Memory management is the art and the process of coordinating and controlling the use of memory in a computer system. Memory management can be divided into three areas: Memory management hardware (MMUs, RAM, etc.); Operating system memory management (virtual memory, protection); Application memory management (allocation, deallocation, garbage collection)."
"Memory management is the art and the process of coordinating and controlling the use of memory in a computer system.
Memory management can be divided into three areas:
Unity Supports automatic memory management, where you don't have to bother about your used assets/objects, Unity's mono engine will release the memory and will use the same for other purposes.In the past, the user has to manually allocate the memory and release it at an appropriate time, which was an overhead.
Even now you can manually remove GameObjects or components of GameObjects at runtime using Destroy Function.
01.
using
UnityEngine;
02.
System.Collections;
03.
04.
public
class
DestroyBasic : MonoBehaviour
05.
{
06.
float
timeDelay=3;
07.
void
Update ()
08.
09.
if
(Input.GetKey(KeyCode.Space))
10.
11.
12.
//Under UnityEngine Namespace
13.
Destroy(gameObject);
14.
//With Time Delay
15.
Destroy(gameObject, timeDelay);
16.
}
17.
18.
DestroyComponent : MonoBehaviour
Destroy(GetComponent<MeshRenderer>());
Destroy is fine... How about DestroyImmediate? Which one to use?
Destroys the object obj immediately. You are strongly recommended to use Destroy instead.
obj
http://docs.unity3d.com/Documentation/ScriptReference/Object.DestroyImmediate.html, explains why.
As defined on https://docs.unity3d.com/Documentation/Manual/UnderstandingAutomaticMemoryManagement.html
Read: https://docs.unity3d.com/Documentation/Manual/UnderstandingAutomaticMemoryManagement.html
Further reading on Automatic Memory Management : http://bit.ly/1gRja5l
I thought of writing about Memory management in unity through C#, but nothing can beat Wendelin Reich's articles in Gamasutra about C# memory Management for unity.
There are three posts on C# memory management: