Unity out of memory with plenty of memory left

I’m running my game in the editor (Pro).

Our IO thread reports an Out of Memory Exception, but both the profiler and Windows task manager show that Unity is using only 1.6 gig with 400 MB system mem still free.

I know for a fact that the IO thread wasn’t trying to allocate a 400 MB large chunk of memory. The crash usually happens in Ionic trying to allocate its internal 16k buffers for processing an archive. (occasionally it happens inside Unity’s own VBO stuff while it’s trying to process a mesh)

How does this happen?

Unity got a few memory leaks here and there, and sometimes freeze and get out of memory all by itself.

We found that using large ScriptableObject directly from the instance existing on disk to be fairly bad, versus loading it, instantiating it, and unloading the original. Frankly, I just have no idea when or why some of those issues occur.

We’ve already experienced the abysmal memory management in Unity and have learned to diagnose these, but why would it go OOM when there’s still system memory available?

Is the last 400 MB of free system memory on my system not classy enough to be considered by Unity? :wink:

Usually, Windows does not allow a single application to allocate more than 75% of the total RAM for itself. Well, last time I checked. 1.6Gb out of 2Gb is 80%…

I have never heard of windows denying memory allocation because it has a certain percentage of physical memory allocated. Googling about that also yields no hits.

I did find http://www.viva64.com/en/k/0036/ which implies that if the unity editor wasn’t compiled with large address references, 1.6gb is close to its theoretical maximum. I’m pretty sure the editor can allocate up to 4 gb on a 64-bit windows machine though, which would disprove that.

I’m on a 64bits computer with 8Gb of RAM, and Unity tends to crash at 1.6Gb… Which would point towards large addresses not being enabled.

As for max allocation;

http://msdn.microsoft.com/en-us/library/windows/desktop/aa366778(v=vs.85).aspx

“Nonpaged pool: 75% of RAM or 2 GB, whichever is smaller.”

The editor is only 32-bit but should be able to allocate up to 4 Gb, this is true. As to your problem… you may have 400 MB of system memory “available” but that doesn’t necessarily mean it’s usable. Windows will reserve some memory for a number of things, including but not limited to: shared video card memory if you’re using an onboard card, device / drivers, sleep mode support, etc. It’s possible that the available memory you have is reserved for system use.

note that also graphics memory need to be adressed with this space.

maybe you have exceeded graphics memory anyway as you write about allocating vbo’s. afaik the graphics memory is not displayed in windows system manager. your best bet would be to use unity profiler (pro feature). there is also a free profiler out there somewhere but i don’t know if it is capable of measuring memory usage.

Only when you use on-board video chip. If you have a video card in a PCI slot, it has its own memory banks and doesn’t affect the RAM. I also remember that prior to Win XP, some of the RAM were allocated for VRAM even if the computer has dedicated VRAM.

Even if you have a card in the PCI / PCIe / AGP slot… if you have an integrated video card as well, memory can still be allocated. If you’re not using the integrated card it should be disabled in the Bios to prevent this.

i’m not talking about shared memory when the graphics device uses the ram instead of its own (not existant) graphics ram. i’m talking about the application beeing able to adress a certain point in memory. and afaik the graphics memory of your video card must also be adressed with the 32 bit memory pointers thus limiting your available adress space for ram. so if you have a 2 gb graphics ram and 4 gb ram the application can still only use 2 gb of ram as it requires half of the adresses for graphics ram. maybe i find a link for this issue later.

a link:
http://www.tomshardware.co.uk/forum/258883-33-graphic-card-stole-memory
http://superuser.com/questions/147007/windows-xp-maximum-memory-reduced-by-graphics-card-memory
http://support.microsoft.com/kb/929605

it seems this issue is gone with windows vista and later because use of a new driver model: http://blogs.msdn.com/b/tmulcahy/archive/2009/02/11/windows-and-video-memory.aspx
i’m confused now. your application has still the issue of not beeing able to adress more than 4 gb in total. the article is talking about overall limits. and it seems from those 4 gb 2 are reserved for the kernel.

have edited quite alot. the last article seems to contain some usefull links at the end. fe to a program which helps you to visualize the use of adress space.
note that even if you have a 64 bit os a 32 bit application like unity can only use 32 bit adress space. and when you run the program in the editor it also requires some memory.

I’m sitting here with Unity currently allocating 3.0 gb of ram. The hard limit of Unity’s allocation is likely to be 4 gigs, ie 32 bit addressing range.

(It died just as I hit 3.3 gigs allocated, according to task manager)