GUI leaks summary

Last days I’ve tested several combinations of GUI stuff to get an idea, what leaks memory and what not. Here is, what I found out:

GUIText: no problems (yeah!).

GUITexture 24-bit RGB / 32-bit RGBA, square dimensions: no problems.

GUITexture 24-bit RGB / 32-bit RGBA, non-square dimensions: leaks.

GUITexture PRVTC 4-Bit, square dimensions: no problems.
(did not test any other PRVTC-combo, because quality is too bad anyways regarding GUI elements …)

GUITexture 16-bit RGB / RGBA, square or non: leaks.

OnGUI (tested an empty OnGUI function): leaks.
Edit: This is a minor leak. You should check your app for yourself with Instruments / Leak and decide what to do.

GUI.xxx: not tested, yet.

Long story short: Use square 24/32-bit images on GUITextures. Use GUIText.

Personally I will continue using OnGUI / GUI.xxx for interface element heavy situations even if it leaks. On the other hand GUI.xxx is a no-go for in-game HUDs, because it’s slower than GUITexture.

Hopefully the 16-bit issues will be fixed soon, because 24-bit isn’t always necessary to show up a nice GUI – saves space, memory and loading time.

Hope that helps,

Jörg

Very useful, thanks!

A n00b-q if I may.

I’ve been looking at the GUI material and I’m confused by what you mean by GUI.xxx! I know I should understand it, but - what exactly do you mean? Do you mean items like GUI.Lablel? If OnGUI is ok, then can’t you say:

function OnGUI() {
	GUI.Label (Rect(0,(480-512),512,512), "", background);
}

Or is that using a GUI.xxx?

And - just for clarification, as I’m new to this - is there any preferred file type for the graphics to use with Unity-iPhone? Or just any square 24 bit will do?

Lastly - have you looked at 8 bits per channel? I find that you can get acceptable images using 8 bits if you’re careful.

I don’t call me Unity pro either :slight_smile:

With GUI.xxx I mean functions like GUI.Button or GUI.Label …
They work, but at least the function OnGUI leaks memory. I think it was something like 11kb, so pretty neclectible in most cases …

AFAIK Unity converts images internally, so it doesn’t matter which format as long as the image shows up in Unity. Important: “square image” means a square image with dimensions of a power of two – 64x64, 128x128, 256x256 etc.

I guess you’re talking about indexed 8-bit images – Unity doesn’t support them.

I guess, I’m a n00b all the way around! :wink: I’ve been saving my images out of Photoshop CS3, and I’ve been using RGB files. I’m given the choice in Image/Mode/RGB Color of: 8 bits/channel, 16 bits/channel and 32 bits/channel. I simply made the assumption that 8 was smaller than 16 or 32, so I’ve been working in that mode/size. They seem to import into Unity as straight .psd files.

joerg, 8 bits per channel = 24bit RGB or 32bit RGBA, which Unity supports just fine.

Of course, I thought Sun Dog was talking about 8-bit indexed images (one channel, 8-bit altogether), which are not supported.

Shows my ignorance! I was just guessing.

Thanks Peter, for explaining that for me.

Thanks Joerg for the help.

That’s really interesting… and terrifying. :cry:

I know this had be asked again and again, and that Unity is hard at work with GDC/Unity2.5 but that would be very helpful for lot of us to know if/when this memory leaks issues will be resolved in the next version of Unity iPhone.
I’m not crazy, I don’t want it to be fixed right now. I just want to know if I must work on another project because the update will not come in the next couple of weeks. Not knowing that is really stressful when you’re near a completed game like ours.

Anyway thanks for the information! :slight_smile:

Thanks Joerg! Helpful data.

Matieu: I can sympathize. I should have had my app in the store by now, but last minute showstopping problems have held it up. I rely heavily on the OnGui(); and GUI.xxx for all the buttons, as I really like the new GUI interface, but Memory issues seem to be one of the prime suspects (http://forum.unity3d.com/viewtopic.php?t=20485). I’ll try going back and reworking my game to remove the OnGui(); in the HUD, but still skuppered for the time being. If you are planning on anything soon, I’d avoid OnGui(); in the game play screens from everything I’ve now read.

here comes the über n00b question:

How do i use GUI without “function OnGUI”?

Just place a GUI Texture in Start() and find out if it was touched by using the mouse functions later?

I should have posted a disclaimer – UT is really doing a great job and GUI stuff works great – the leak I detected is a minor one. So before you start changing your project you should check for yourself using Instruments / Leak and decide what to do.

To answer your question: place a GUITexture in your scene, add a script to the GUITexture with something like:

function Update() {
  if (Input.GetMouseButtonDown(0)  guiTexture.HitTest(Input.mousePosition)) {
        // do something
  }
}

There are more elegant ways to do this, like:
http://forum.unity3d.com/viewtopic.php?t=16373&highlight=guitouchcontroller

VIC20:

Check out this thread:
http://forum.unity3d.com/viewtopic.php?t=16373

There is a C# script I just converted to .js that gets around the problems with mouseup mousedown being unavailable on the iphone.

Also look into touchphases, which I haven’t looked at at all. Touchphases are the iPhone classes for tracking touches, swipes, pinching, etc…

Are there any statistics that proof this leak and show to which degree it goes?

Because nonsquare texture means that unity has to create a new texture thats square pow 2 and copy your texture in.

The statistics would be interesting for the following reason: does the leak represent the added part or is it actually the original texture that was required to be expanded that leaks?

Also, did you set the texture to be resized to the required format or not in the import settings.

We have fixed number of reported memory leaks by now. So you will definitely get it with the next release.

If you have issues which prevents you to release a game - you should contact our support and you will get a “custom” build.

Thanks ReJ! :slight_smile: