Hello,
I am getting the following after running a server for 1-2 days. This error was when running in the editor, but I notice the same even when running the server in batchmode. It will start around 60mb but the commit will grow to around 2gb+ before crashing due to out of memory.
![](//forum.arongranberg.com/uploads/default/255/56385ca9ca6858e6.png)
It’s strange, because line 174 is simply setting the new transform (tr.position).
It seems like Unity3d utilizes a dynamic array internally for set_position and it continues to grow over time.
This is with 32 AI active using the RVOController system.
I did not get any response on the Unity Support forums so I’m wondering if anyone has any idea what might cause this. I’m using 4.1.0f of Unity and the latest version of the Pathfinding Project.
Thanks!
Hm… no idea.
Could you try running it without pathfinding.
Also, are you using pathfinding pooling? Are you updating the graphs during runtime?
I’m not pooling but also there is no pathing occurring during this time.
Normally the AI would be disabled when it does not have a target, but I had this functionality turned off to test something and that is when I noticed the issue.
The graph is not being updated at runtime.
I will try with pooling and then with pathfinding disabled, but I imagine since pathing is not occurring it wont make a difference.
Looks like I enabled everything for the AI but AIPath was still disabled so I think that can be counted out.
Based on the fact that it is Unity’s internal set_position method trying to allocate the huge (2gb) amount of space for the dynamic array, I’d say it is an issue with Unity. It is strange to me though as I can’t imagine there would be such an issue with the most commonly used functionality. I also have not heard of anyone else experiencing this issue with transform.position.
I will have to create a new project that spawns hundreds of gameobjects with script attached that simply sets transform.position every update to see if I can reproduce it without anything else.
I don’t think set_position necessarily is the bad thing here. It just happened to be the last function to be called before some array needed resizing. Possibly the managed C# environment allocated a new large block of memory to use (though 2Gb is a bit much).
Also, try disabling local avoidance, hopefully that has no memory leaks, but you never know.
I found out what the issue is. It ended up being a Unity bug, but as you said, not caused by setting transform.position.
I found out that running a scene without a camera (either in editor with no cameras or running in batchmode, which disables cameras) while there is an active mesh renderer causes a memory leak. This only seems to happen with highpoly meshes.
Others have experienced this problem:
http://forum.unity3d.com/threads/145234-Batchmode-memory-leak-and-fix
Disabling the mesh renderer on the AI and client prefabs solved the problem.
Edit: Wish I could mark this is the answer so it doesn’t seem like local avoidance was the issue. ![:stuck_out_tongue: :stuck_out_tongue:](//forum.arongranberg.com/images/emoji/twitter/stuck_out_tongue.png?v=5)
Edit 2:
This memory leak can easily be reproduced (leaks about 200kb/s for me) by doing the following:
Create a new project, delete the camera in the scene, add a new game object to the scene, attach this script:
using UnityEngine;
using System.Collections;
public class TestSpawner : MonoBehaviour {
public GameObject testPrefab;
public int spawnCount = 512;
public int counter = 0;
void Update () {
while (counter < spawnCount)
{
Instantiate(testPrefab);
counter++;
}
}
}
Create a prefab. Attach a high-poly model (low poly models either don’t leak or leak too slowly for ease of reproducing this leak). I used the char_astrella model that comes with the free tutorial project Unity Labs 01: Robot Lab from the asset store. It’s around 26k tris. I’ve tested it without the animator and materials just in case.
Assign the prefab to the TestSpawner’s TestPrefab variable and you’re set. I have tested this with 4.1.5f.