I have a simple application that It needs to run for 10 hours per day. Don't ask why!!! I am not a programmer so i am not really aware about what happens with memory management variables or background logs in unity. I have some gui variables like that ... there are loads more to be honest ..
If i declare the variables in OnGUI and do a debug log the variables are called every frame. How unity is working if i am not using debug log? does it just replaces a few numbers every frame or it keeps a log of them? In around 7 hours the application crashes ! So i must have a memory leak or some sort of logging overflow ... Is there any way to figure out what is going on ? IT might be even a computer problem ...
The ideal would have been to put these variables in an update or onGUI and calculate screen.width ONLY when the user tries to resize. something like
or getting a value from awake naming it initialScreenWidth and
Should i worry about declaring variables OnGUI or there is no problem ... ?I am not sure where to begin really ... any suggestions?
asked Sep 10 '10 at 04:42 PM
None of the lines of code you show should allocate any amount of memory that matters. They are integers, not objects, and you are allocating them in local variables in OnGUI- they go away when the method exits.
The kinds of lines you should be worried about allocate objects that don't get cleaned up. They would tend to be game objects stored in the scene (for example, if you called Instantiate) or objects added to arrays, text being appending to a string over and over again... something like that.
If you haven't already, verify that memory allocation is in fact the problem. Run your app the same way it's being run when it crashes, and monitor it (on Mac use Activity Monitor, on Windows use Task Manager.) If memory is the problem you should see the memory footprint go up significantly after half an hour. There are many reasons an application can to crash, for example, if it accesses a network or network resource that gets shut down every night.
If you have any specifics about the crash you should post them. Try reproducing with a debug build, maybe you'll get some better information from the crash.
answered Sep 10 '10 at 06:46 PM