Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8712641
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T05:09:04+00:00 2026-06-13T05:09:04+00:00

Searching Google and StackOverFlow comes up with a lot of references to this question.

  • 0

Searching Google and StackOverFlow comes up with a lot of references to this question. Including for example:

Ways to determine size of complex object in .NET?

How to get object size in memory?

So let me say at the start that I understand that it is not generally possible to get an accurate measurement. However I am not that concerned about that – I am looking for something that give me relative values rather than absolute. So if they are off a bit one way or the other it does not matter.

I have a complex object graph. It is made up of a single parent (T) with children that may have children and so on. All the objects in the graph are from the same base class. The childrean are in the form of List T.

I have tried both the serializing method and the unsafe method to calculate size. They give different answers but the ‘relative’ problem is the same in both cases.

I made an assumption that the size of a parent object would be larger than the sum of the sizes of the children. This has turned out not to be true. I calculated the size of the parent. Then summed the size of the children. In some cases this appeared to make sense but in others the sum of the children far exceeded the size determined for the parent.

So my question is: Why is my simple assumption that serializing an object can result in a size that is less that the sum of the children. The only answer I have come up with is that each serialized object has a fixed overhead (which I guess is self evident) and the sum of these can exceed the ‘own size’ of the parent. If that is so is there any way to determine what that overhead might be so that I can take account of it?

Many thanks in advance for any suggestions.

EDIT
Sorry I forgot to say that all objects are marked serializable the serialization method is:

var bf = new BinaryFormatter();
            var ms = new MemoryStream();
            bf.Serialize(ms, testObject);
            byte[] array = ms.ToArray();
            return array.Length;
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T05:09:05+00:00Added an answer on June 13, 2026 at 5:09 am

    It will really depend on which serialization mechanism you use for serializing the objects. It’s possible that it’s not serializing the children elements, which is one reason why you’d see the parent size smaller than the sum of the children (possibly even smaller than each individual child).

    If you want to know the relative size of an object, make sure that you’re serializing all the fields of all objects in your graph.

    Edit: so, if you’re using the binary formatter, then you must look at the specification for the format used by that serializer to understand the overhead. The format specification is public, and can be found at http://msdn.microsoft.com/en-us/library/cc236844(prot.20).aspx. It’s not very easy to digest, but if you’re willing to put the time to understand it, you’ll find exactly how much overhead each object will have in its serialized form.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Sorry if this is a newbie question, searching google and SO turns up nothing,
I know this question can be answered by searching in google. But I have
I have been searching a lot on Google and Stackoverflow for soltuions on how
I've searching for this for a while now online (Google, and StackOverflow), but haven't
Searching Stackoverflow on Google I get this result: Inspecting the HTML source of the
I've been searching Google and StackOverflow exhaustively and cannot find this. Maybe I'm missing
I've been searching on Google for a resolution to this problem, but cannot find
After searching stackoverflow and Google for the past hour I thought I would ask.
I've been trying to solve this out for about 4 hours (searching on google
I've tried searching all over StackOverflow and Google and I've found ideas that I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.