Re: Memory leak in BinaryFormatter?

Tech-Archive recommends: Fix windows errors by optimizing your registry

From: Justin Rogers (Justin_at_games4dotnet.com)
Date: 11/21/04


Date: Sun, 21 Nov 2004 13:51:19 -0800

You can force the GC to collect. Your issue here is that the Serialization
engine is doing
a lot of work to serialize something large like a data set. Not to mention you
don't talk
about where you store the formatted serialized data... If you are writing out to
a disk file
then you probably won't reach epic memory consumption, but writing into memory
you
just might. Remember that:

1. All types names and assembly names get formatted into the serialized data.
2. Every string becomes +1-5 bytes for an appended length.
4. Certain things appear to be aligned on certain boundaries.

As for the overhead of the serialization engine, a bit of reflection is being
used, they are
still storing the final as XML and not real blitted types, they are storing a
schema and
a diff gram, and they are estimating the system of the string builder, so if
they estimate
a large size to begin with, and then have to grow one or more times, you end up
with
a lot of wasted memory.

-- 
Justin Rogers
DigiTec Web Consultants, LLC.
Blog: http://weblogs.asp.net/justin_rogers
"Martin Lessard" <Martin Lessard@discussions.microsoft.com> wrote in message 
news:EF6A6790-515D-4CB3-A683-03BA0B7540C2@microsoft.com...
>I try to serialize a dataset with the BinaryFormatter.  The size of the
> dataset is about 23mb.  When i call the serialise method of the
> BinaryFormatter, the memory used by my process goes from 51500k to 256736k as
> reported by the task manager and there is nothing i can do to reclaim this
> memory.  Is there a memory leak in this method? 


Relevant Pages

  • Re: share a structure array containing multidimensional char array
    ... When you want to deserialize/serialize a managed type to/from unmanaged memory, you have to use the same serializer/deserializer at both sides, that means you also need to use .NET to serialize/deserialize at the C++ side. ... Besides the structures, you also have to store the number of structures serialized to the shared memory buffer and the size of the individual structure members, without this info it's impossible for the reader to determine the number of array members and the size of the structure members. ... HANDLE hKernel; ... > Mapping a datastructure, whatever it's type, in a serialization. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: share a structure array containing multidimensional char array
    ... memory, you have to use the same serializer/deserializer at both sides, that ... Deserialization Error: ... C++ code doesnot make any serialization. ... instance as an int value at the start of the MM segment. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Write class/struct object to file
    ... the code can not directly access memory which is totally ... Serialization feature as Sam suggested. ... Here are some articles introducing .net binary serialization: ... Microsoft MSDN Online Support Lead ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: How do I measure the size of a dataset?
    ... I am concern about the web server memory that this dataset might occupy. ... The memory that a dataset occupies might not be equal with the size of the dataset's serialization result ... Microsoft Online Community Support ... where an initial response from the community or a Microsoft Support ...
    (microsoft.public.dotnet.framework.adonet)
  • How do I copy NONSERIALIZED fields and properties of an object?
    ... To make deep clone of object I often use a serialization ... memory, to make a copy. ... Public Sub CopiaFieldsNotSerialized(ByVal Destinazione As Object, ... - Another problem is breaking circular reference. ...
    (microsoft.public.dotnet.framework.performance)