Code and memory profiling for .NET developers.
Moderators: Brian Donahue, richardjm, Bart Read, StephenC
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?
- Posts: 1
- Joined: Thu Dec 18, 2008 4:49 pm
Value types like booleans won't show up in the memory profiler unless they have been boxed by .NET, as in all other cases they will be part of other classes and not visible as distinct objects.
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.
Red Gate Software Ltd.
- Posts: 134
- Joined: Thu Aug 17, 2006 3:44 pm
Return to ANTS Profiler Previous Versions
Who is online
Users browsing this forum: No registered users and 1 guest