What is the size of a heap-allocated Object in .net, including management overhead? I'm assuming Objects are allocated along 4-byte boundaries, or is a different approach used?
Asked
Active
Viewed 2,211 times
5
-
See: http://stackoverflow.com/questions/324053/find-out-the-size-of-a-net-object – Jon B Mar 10 '09 at 19:13
-
Jon B: That question is about the size of any object in .NET while this question is about the size of instances of the .NET Object class. A totally different question. – Tamas Czinege Mar 10 '09 at 19:20
2 Answers
5
4 byte boundaries on x86. Possibly 8 byte boundaries on x64.
There's an 8 byte overhead on x86, for a type reference and a sync block. I wouldn't be surprised to find that's 12 or 16 bytes on x64.
For some reason, on x86 an instance of just System.Object
appears to take 12 bytes, making 12 bytes the absolute minimum size possible - but a class with an int
also takes 12 bytes. I've no idea why this is the case.

Jon Skeet
- 1,421,763
- 867
- 9,128
- 9,194
-
You shouldn't be able to answer the high AND low level questions so well. I'm retaging with a new tag: stump-the-skeet. In this case, this question is the stump-the-skeet:fail. – Michael Meadows Mar 10 '09 at 19:19
-
-
1
Depends on a machine, on 32 bit machine it is usually 4-bytes. However, on 64 bit box, it is 8-bytes, and so on.
-
2I think you're talking about the size of a *reference* rather than the object overhead itself. – Jon Skeet Mar 10 '09 at 19:15