Unity Memory Issues

Dear anyonethatreads,

Unity has a profiler. This has a variable: Profiler.usedHeapSize. This is equal to the Total Allocated in the profiler window.

The Unity Manual says: "Total Allocated is the total RAM used by the application. "

Allocating a float[1024,1024] will not make the Profiler.usedHeapSize increase, but instead the System.GC.GetTotalMemory increases by 4 Mb. Okay.

So, now we have two places to look for memory. Fine.

If we now allocate a Texture2d(1024, 1024) and apply it uncompressed this should make the Profiler.usedHeapSize increase about 4Mb and not increase the Sysete.GC.GetTotalMemory. It does.

But now the memory used by the application is increased about 10Mb. Fine, maybe Unity allocates a lot of memory that it can use at a later date. No.

When I continue to allocate textures the program crashes when I reach the limit for a 32-bit application. And the Profiler.usedHeapSize says: “Nah, you’re only using 1.5Gb of memory, your fine, chill dude”.

It appears to me that allocating a 1024 by 1024 texture uncompressed should take 4Mb, not 10Mb. The profiler agrees with me. But the application uses 10Mb.

Now this would be fine, but on top of this Unity leaks a lot of memory. This gets more extreme the bigger the project gets and I don’t know how to fix it!?

In my project the Profiler.usedHeapSize never goes above 1Gb and the System.GC.GetTotalMemory never goes above 70Mb. But it eventually crashes because it ran out of memory.

I have submitted this as a bug report, but I hope this isn’t a bug and the first response in this thread will be: "Go in to the checkbox settings->useshitloadsofmemory and uncheck it”.

For anyone that’s interested: Here is a project that has a memory leak: http://dl.dropbox.com/u/4359354/MemoryBug.zip

Best regards,
Johan

Hey Johan

The memory reported by Profiler.usedHeapSize is the memory we are able to track in Unity. Unfortunately we don’t have a way to intercept the allocations directX and openGL are making, so when you make a texture, the driver will allocate memory for that including the mipmaps (acounting for the additional 6MB). I’ll fix up the documentation on this.
We are continuously improving on these tools, and appreciate your feedback on this.

Regarding the memory leak: I’ll start investigating ASAP :slight_smile:

Best regards,
Kim

Hi
I’ve run the project you attached, and it is true that the memory reported is off because of the incorrect tracking, but I have not been able to find any leaks.
Best regards,
Kim