RE: XmlSerialization Object Memory Usage



Dave,
Sorry, I realized after posting that I had been too close to the problem
and my description wasn't completely accurate.

I am creating an object over and over again and adding the new copy to a
hashtable.

So
Hashtable Storage
for( int i = 0; i < 1000; i++ )
{
ComplexObj Obj1 = new ComplexObj();
Storage.Add( i, Obj1 );
}

In one scenario I would manually set the properties of the object, in
another scenario I would have serialized a copy of the object and I would be
reading it in instead of new ComplexObj(). In both cases I have a 'deep
clone' written which creates a 'new' object of the main type and then of the
one complex type that it contains, populates this new object with the values
from itself and then returns that.

I'm measuring the size with the CLR Profiler. It gives me an accurate count
of objects, and a memory size of these objects. It doesn't make sense that
the size of these four 'versions' of exactly the same thing display 4
different sizes.

It's a console app that creates all this and then waits. I show heap with
CLR Profiler and that is where I'm getting the measurements. Do you have a
better mechanism for seeing .NET memory usage?
Any assistance you can offer would be appreciated.
Thanks,

"Dave Hiniker - MSFT" wrote:

Could you clarify the contents of the object (what makes it hundreds of K)?
And how are you measuring the memory overhead in each case? Thanks!

"Michael Cline" wrote:

Framework 1.1
Our environment requires us to deserialize xml messages into objects.

In doing some memory analysis I've found the following that doesn't make any
sense to me so I was hoping someone could shed some light on the issue.

Simple Object contains a string, int and bool, as well as another complex
object that also contains a string, int and bool.

If I use code to loop through and create identical objects and add them to a
Hashtable, I see each object taking 430K

If I put a method within that object that 'clones' it and returns a new
object, the new object is only 234K.

Changing the scenario to using the XmlSerializer to deserialize the object
from a string, my memory size of a single object grows to 1016K.

If I call my 'clone' method on this object the size is reduced to 488K.

In my simple mind all of these instances are identical, however there are 4
different sizes which cover a large range.

I'm thinking of creating a CodeGeneration application that could create my
'clone' methods for me, but wanted to make sure that what I was seeing had
some logical justification behind it.

Also, does this behavior change in .NET 2.0 or 3.0? Is there any way for me
to get my 'deserialized' version of the object to be down to the 234K size?

Thanks
.



Relevant Pages

  • RE: XmlSerialization Object Memory Usage
    ... reading it in instead of new ComplexObj(). ... and a memory size of these objects. ... Simple Object contains a string, int and bool, as well as another complex ... If I call my 'clone' method on this object the size is reduced to 488K. ...
    (microsoft.public.dotnet.framework.performance)
  • Re: Out of Memory exception when trying to Clone a Bitmap
    ... Gdiplus will only allocate memory when the image is actually accessed. ... Since you are using a third party sdk, it seems that when gdiplus attempts ... If I clone using the EXACT bounds of the original bitmap it works fine. ...
    (microsoft.public.win32.programmer.gdi)
  • Re: Copy-on-Write memory management
    ... allocate a block of memory, write some data to it, and then clone it ... increase in my footprint in the system memory until it was necessary ... patterns have facilities which make this less difficult than it would ...
    (comp.programming)
  • Re: A question about Gwen and Normans kids
    ... BEcause I was thinking they could use the Gwen clone, ... memory in MJ's mind to create the story. ... what happened to the Gwen clone. ...
    (rec.arts.comics.marvel.universe)

Loading