Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I don't know how you use that code, but one thing that strikes me is that you don't release your resources. For instance, if you call <code>Serialize(obj)</code> a lot of times with a lot of large objects, you will end up having a lot of memory being used that is not released directly, however the <code>GC</code> should handle that properly, but you should always release your resources.</p> <p>I've tried this piece of code:</p> <pre><code>public static byte[] Serialize(object obj) { Type type = obj.GetType(); DataContractSerializer dcs = new DataContractSerializer(type); using (var stream = new MemoryStream()) { dcs.WriteObject(stream, obj); return stream.ToArray(); } } </code></pre> <p>With the following <code>Main</code>-method in a Console Application</p> <pre><code>static void Main(string[] args) { var filipEkberg = new Person {Age = 24, Name = @"Filip Ekberg"}; var obj = Serialize(filipEkberg); } </code></pre> <p>However, my <code>byte</code>-array is not nearly as big as yours. <a href="https://stackoverflow.com/questions/796719/c-compact-framework-outofmemoryexception-with-xmlserializer-serialize">Having a look at this similar issue</a>, you might want to consider checking out <a href="http://code.google.com/p/protobuf-net/" rel="nofollow noreferrer">protobuf-net</a>.</p> <p>It might also be interesting to know what you are intending to do with the serialized data, do you need it as a <code>byte</code>-array or could it just as well be XML written to a text-file?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload