Memory size of Boolean
palelocust
Posts: 2
I'm memory profiling an application and as I was scrolling through the data I noticed that System.Boolean objects are showing a size of 12 bytes. I thought, though, the size of a boolean in C# was 1 byte (http://msdn.microsoft.com/en-us/library/eahchzkf.aspx)
So what is causing the extra 11 bytes to show up in Memory Profiler?
Thanks
So what is causing the extra 11 bytes to show up in Memory Profiler?
Thanks
Comments
A boxed boolean will have 8 bytes of .NET header, 1 byte of boolean and 3 bytes to make the size a multiple of 4 (exactly the same as a class containing a single boolean field). This makes them quite inefficient to store as objects - if you consider the fact that you also need to have at least one reference to this boolean the total memory required is actually 16 bytes per boolean.
Software Developer
Red Gate Software Ltd.