- Home /
Is using new GUIContent() in Unity causes memory leaks?
If I do not make GC.collect(), Is using new GUIContent() in Unity causes memory leaks like creating new classes? I'm interested in this question cose of found this thing in unitydoc, I heard about automatic memory managment, but does not this code will increase the frequency of them?:
void OnGUI() {
GUI.Button(new Rect(0, 0, 100, 20), "Click Me");
GUI.Button(new Rect(0, 30, 100, 20), new GUIContent("Click Me"));
}
Hi I dont think so did you try using profilier if donot have pro just go to stats and ths PFs before and after using GUI Contnet
I have got a unity free, and there is not profiler, but thanks for the idea
Answer by Eric5h5 · Mar 22, 2013 at 07:03 AM
No, structs are allocated on the stack. Also, please don't misuse the term "memory leak". That refers to memory which is never reclaimed.
E, would you say it's better to just edit-awat such incorrect ter$$anonymous$$ology?
Or is it more instructive if the incorrect ter$$anonymous$$ology remains on the board, with a note such as you have added?
try to err on the side of caution when editing ter$$anonymous$$ology.. without the misleading context, Eric's answer would fail to enlighten the rest of us!
@Eric5h5 you make this seem too simple :/
It is pretty simple really. :) I've sometimes seen a tendency for people to say "memory leak" when they're just referring to memory allocation. Allocating memory is fine, as long as it's released when no longer used (and since Unity is a managed environment, I'm not sure it's even possible to cause a memory leak with scripts, unless you're triggering a bug in Unity itself).
Of course, repeatedly allocating too much memory can lead to the garbage collector running frequently, which you'd generally want to avoid. So you'd try not to do allocations unnecessarily, but even if you do, it's not a serious problem like a memory leak. Deallocating memory on the stack is really cheap, though, since it's just moving the stack pointer and doesn't involve garbage collection.
Can you modify your answer and move your coment into it, your coment gives more info then the answer ? =) btw Before I've started using unity I'd never used managed environment (mono/.Net/Java)
Your answer
![](https://koobas.hobune.stream/wayback/20220613094833im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Car enter and exit script not working 1 Answer
health problem 1 Answer
Disable GameObject Only Father Not Children 2 Answers
Weird problem with gunscript 2 Answers