Is Destroy (gameobject) leaking memory?

I created a simple test in an empty project with an empty scene (just the one script on the default camera). The test uses a button to create 1000 empty game objects, and then a different button to destroy them. The project builds to iOS and I used Xcode’s profiler for checking the memory.

Results: (for each entry I wait 30 seconds before moving on)

  • start 8.8 MB to 9.1 MB
  • create 9.7 MB to 9.8 MB
  • destroy 9.8 MB
  • create 9.9 MB
  • destroy 9.8 MB
  • create 10.1 MB
  • destroy 10 MB

Next I just quickly alternated create and destroy and the memory rose to 11.1 MB before I was quit. I would like to know if this was somehow expected behavior or if I did something wrong. Here is the script that I used:

using UnityEngine;
using System.Collections;
using System.Collections.Generic;

public class MemoryLeakScript : MonoBehaviour 
{
	List<GameObject> _instances = new List<GameObject>();
	string _display = "";
	
	void OnGUI ()
	{
		if (GUI.Button( new Rect(10, 10, 100, 30), "Create"))
		{
			Create();
		}
		
		if (GUI.Button( new Rect(10, 50, 100, 30), "Destroy"))
		{
			Kill();
		}
		
		GUI.Label( new Rect(120, 10, 100, 30), _display);
	}
	
	void Create ()
	{
		for (int i = 0; i < 1000; ++i)
		{
			GameObject obj = new GameObject("dummy");
			_instances.Add( obj );
		}
		_display = string.Format("{0} objects", _instances.Count);
	}
	
	void Kill ()
	{
		for (int i = _instances.Count - 1; i >= 0; --i)
		{
			GameObject.Destroy( _instances *);*
  •  }*
    
  •  _instances.Clear();*
    
  •  _display = string.Format("{0} objects", _instances.Count);*
    
  • }*
    }

Unity objects are not part of Mono and are not subject to garbage collection. You can use Resources.UnloadUnusedAssets.

So I know this is 3 years old now but I had this same problem and figured I’d answer for anyone that had the same issues as me.

You need to use Destroy() not GameObject.Destroy();

EDIT:
As was pointed out below this answer is actually wrong. I changed a few things at once turns out what was actually fixing it for me was that I had to destroy my procedural generated meshes explicitly using

    Destroy(gameObject.GetComponent <MeshFilter>().sharedMesh);
    Destroy(gameObject.GetComponent<MeshFilter>().mesh);

sorry for the false answer, thanks for correcting me.