- Home /
Ubuntu linux, Headless mode ,Memory Leak!! why?
hi,I need some help . I write a physicalServer used unity3d and run it on linux platform , and with "headless" mode, then the memory raise up to 3.5 GB quickly ! then I try run a noraml version without "headless", 24h has past and the memory stay between 300MB --- 350MB(no memory leak). So, who knows why the memory leak under "headless mode" ? how can I to improve ? thank you
Looks like executing Resources.UnloadUnusedAssets() from time to time helps. But I have also made some other changes so I am not sure at the moment if this is the key point.
I have also added this piece of code to run from time to time:
var textures : Texture[] = Resources.FindObjectsOfTypeAll(Texture);
for (var i = 0; i < textures.length; i++)
{
//Debug.Log(textures[i].name + " __ " + textures[i].hideFlags);
if (textures[i].hideFlags == HideFlags.NotEditable ||
(textures[i].hideFlags == HideFlags.None && textures[i].name != "")
)
{
//Debug.Log(textures[i].name + " __ " + textures[i].hideFlags);
Resources.UnloadAsset(textures[i]);
textures[i] = null;
}
}
And the last thing I did, was to avoid String addition, because it allocates memory. It's better to use System.Text.StringBuilder.
Answer by robertono · Jan 07, 2016 at 10:12 PM
Maybe there is shader or any graphycs on scene, whose causing memory leak ?
Two months passed.. Have you solved the problem?
I'm just going to host unity server on ubuntu using "headless" mode, so that's why im interested.
@robertono In actually I found the key point but I can not solve the problem whaterver you have anything need to render or not ,you must keep a camera in scene under headless mode
So when you add the camera to the scene, the memory leak disappears? (I have this problem too).
No, he says that he always has a camera, but in the normal mode (without argument "headless") app works O$$anonymous$$, without any memory leak (as I understood).
You need to post this bug to the issue tracker, I think. I would vote for it
Answer by MariuszKowalczyk · Jan 11, 2016 at 07:19 PM
Removing all OnGUI() functions from the code solved this problem for me. Not only the inside of the function, remove the whole function. You can use the following method:
#if IS_DEDICATED
function OnGUI()
{
}
#endif
Then you have to define IS_DEDICATED in ProjectSettings>Player>Scripting Define Symbols.
Hmm. I start to suspect, that this is not actually a bug. As you know, it takes time for the garbage collector to run. So if the memory is not needed by other applications, then there is no point to run the garbage collector. And maybe this is the purpose of the memory increase.
Like I said, just "maybe". And another "maybe": maybe to fix this "issue" you just need to run garbage collector by yourself when the server is for example empty.
Anyway, these above are just my free thoughts, I will verify them soon. And I think like I am wrong and there is actually a bug.
You should avoid allocating memory during the game. In my case the increase is due to allocating when new player connect to the server and destroy when he is gone. It may also be due to other operations that allocate memory like string addition etc. I am sure, because I have tested. When the server is with password and no one can connect, there is no memory growth. I have just made a fix to this and will tell you if it helped.
To avoid string addition use: System.Text.StringBuilder $$anonymous$$ore info here: http://docs.unity3d.com/$$anonymous$$anual/UnderstandingAutomatic$$anonymous$$emory$$anonymous$$anagement.html
If you want to see Unity Legacy Networking with Dedicated Servers in action, I invite to my game Ball 3D (www.ball3d.com).
Hello Any updates on this ? Have you checked by yourself ? Whats the results ?
Thanks
Your answer
Follow this Question
Related Questions
Performance going down over time 2 Answers
Mesh memory leak 3 Answers
Mesh Destroy After an Editor Stop 0 Answers
m_Memory.renderTextureBytes<0 1 Answer
Memory Leak Help 2 Answers