Where is memory leak (Serialize object)Should I call Close() or Dispose() for stream objects?Do static members ever get garbage collected?XmlSerializer.FromTypes producing memory leaks?Deep cloning objectsSerializing to JSON in jQueryConvert form data to JavaScript object with jQueryUsing StringWriter for XML SerializationActivity has leaked window that was originally addedDeserialize JSON into C# dynamic object?Creating a memory leak with JavaperformSelector may cause a leak because its selector is unknownSerializing Arrays in C#Serialize object to XML, no namespace, can read Interface property
What was this official D&D 3.5e Lovecraft-flavored rulebook?
Non-trope happy ending?
It grows, but water kills it
Problem with TransformedDistribution
How do I find all files that end with a dot
Should I outline or discovery write my stories?
How do I color the graph in datavisualization?
Are paving bricks differently sized for sand bedding vs mortar bedding?
"Spoil" vs "Ruin"
How to implement a feedback to keep the DC gain at zero for this conceptual passive filter?
What does routing an IP address mean?
Added a new user on Ubuntu, set password not working?
Has any country ever had 2 former presidents in jail simultaneously?
Why is so much work done on numerical verification of the Riemann Hypothesis?
Why can Carol Danvers change her suit colours in the first place?
Lowest total scrabble score
Yosemite Fire Rings - What to Expect?
Pre-mixing cryogenic fuels and using only one fuel tank
How do you respond to a colleague from another team when they're wrongly expecting that you'll help them?
How can "mimic phobia" be cured or prevented?
Freedom of speech and where it applies
How to explain what's wrong with this application of the chain rule?
Are the IPv6 address space and IPv4 address space completely disjoint?
Does a 'pending' US visa application constitute a denial?
Where is memory leak (Serialize object)
Should I call Close() or Dispose() for stream objects?Do static members ever get garbage collected?XmlSerializer.FromTypes producing memory leaks?Deep cloning objectsSerializing to JSON in jQueryConvert form data to JavaScript object with jQueryUsing StringWriter for XML SerializationActivity has leaked window that was originally addedDeserialize JSON into C# dynamic object?Creating a memory leak with JavaperformSelector may cause a leak because its selector is unknownSerializing Arrays in C#Serialize object to XML, no namespace, can read Interface property
I have this method:
public static string XmlSerialize<T>(T data)
string result;
using (StringWriter stringWriter = new StringWriter())
XmlWriterSettings settings = new XmlWriterSettings
Encoding = Encoding.UTF8,
OmitXmlDeclaration = true,
;
using (XmlWriter writer = XmlWriter.Create(stringWriter, settings))
XmlSerializerNamespaces ns = new XmlSerializerNamespaces();
ns.Add("", "");
XmlSerializer serializer = XmlSerializer.FromTypes(new[] typeof(T) )[0];
serializer.Serialize(writer, data, ns);
result = stringWriter.ToString();
return result;
This is simple method to serialize object into xml. But this method have memory leak, and I haven't idea where is it.
Can anyone help me find it?
c# serialization memory-leaks
|
show 6 more comments
I have this method:
public static string XmlSerialize<T>(T data)
string result;
using (StringWriter stringWriter = new StringWriter())
XmlWriterSettings settings = new XmlWriterSettings
Encoding = Encoding.UTF8,
OmitXmlDeclaration = true,
;
using (XmlWriter writer = XmlWriter.Create(stringWriter, settings))
XmlSerializerNamespaces ns = new XmlSerializerNamespaces();
ns.Add("", "");
XmlSerializer serializer = XmlSerializer.FromTypes(new[] typeof(T) )[0];
serializer.Serialize(writer, data, ns);
result = stringWriter.ToString();
return result;
This is simple method to serialize object into xml. But this method have memory leak, and I haven't idea where is it.
Can anyone help me find it?
c# serialization memory-leaks
3
Why have you decided this method has memory leak? What makes you think so?
– Andy Korneyev
Dec 1 '16 at 12:26
1
Can´t see anything here that can´t be handled by GC when leaving the method. So why do you think there is a memory-leak?
– HimBromBeere
Dec 1 '16 at 12:31
Because when I used this method to serialize one object 10 000 times, memory used by program up to 100MB (from 10MB).
– Lasoty
Dec 1 '16 at 12:35
That doesn´t mean it´s not released. Garbage collection is undeterminstic, you can´t say when it´s finished andf thus when your memory is relased, only that it happens. Anyway: how did you determine it uses 100MB? Don´t trust TaskManager too much when it comes to Memory.
– HimBromBeere
Dec 1 '16 at 12:37
1
code looks fine to me, but you can read more here: stackoverflow.com/questions/7524903/…
– Thomas Koelle
Dec 1 '16 at 12:40
|
show 6 more comments
I have this method:
public static string XmlSerialize<T>(T data)
string result;
using (StringWriter stringWriter = new StringWriter())
XmlWriterSettings settings = new XmlWriterSettings
Encoding = Encoding.UTF8,
OmitXmlDeclaration = true,
;
using (XmlWriter writer = XmlWriter.Create(stringWriter, settings))
XmlSerializerNamespaces ns = new XmlSerializerNamespaces();
ns.Add("", "");
XmlSerializer serializer = XmlSerializer.FromTypes(new[] typeof(T) )[0];
serializer.Serialize(writer, data, ns);
result = stringWriter.ToString();
return result;
This is simple method to serialize object into xml. But this method have memory leak, and I haven't idea where is it.
Can anyone help me find it?
c# serialization memory-leaks
I have this method:
public static string XmlSerialize<T>(T data)
string result;
using (StringWriter stringWriter = new StringWriter())
XmlWriterSettings settings = new XmlWriterSettings
Encoding = Encoding.UTF8,
OmitXmlDeclaration = true,
;
using (XmlWriter writer = XmlWriter.Create(stringWriter, settings))
XmlSerializerNamespaces ns = new XmlSerializerNamespaces();
ns.Add("", "");
XmlSerializer serializer = XmlSerializer.FromTypes(new[] typeof(T) )[0];
serializer.Serialize(writer, data, ns);
result = stringWriter.ToString();
return result;
This is simple method to serialize object into xml. But this method have memory leak, and I haven't idea where is it.
Can anyone help me find it?
c# serialization memory-leaks
c# serialization memory-leaks
edited Dec 1 '16 at 16:33
TheLethalCoder
5,52962648
5,52962648
asked Dec 1 '16 at 12:24
LasotyLasoty
1614
1614
3
Why have you decided this method has memory leak? What makes you think so?
– Andy Korneyev
Dec 1 '16 at 12:26
1
Can´t see anything here that can´t be handled by GC when leaving the method. So why do you think there is a memory-leak?
– HimBromBeere
Dec 1 '16 at 12:31
Because when I used this method to serialize one object 10 000 times, memory used by program up to 100MB (from 10MB).
– Lasoty
Dec 1 '16 at 12:35
That doesn´t mean it´s not released. Garbage collection is undeterminstic, you can´t say when it´s finished andf thus when your memory is relased, only that it happens. Anyway: how did you determine it uses 100MB? Don´t trust TaskManager too much when it comes to Memory.
– HimBromBeere
Dec 1 '16 at 12:37
1
code looks fine to me, but you can read more here: stackoverflow.com/questions/7524903/…
– Thomas Koelle
Dec 1 '16 at 12:40
|
show 6 more comments
3
Why have you decided this method has memory leak? What makes you think so?
– Andy Korneyev
Dec 1 '16 at 12:26
1
Can´t see anything here that can´t be handled by GC when leaving the method. So why do you think there is a memory-leak?
– HimBromBeere
Dec 1 '16 at 12:31
Because when I used this method to serialize one object 10 000 times, memory used by program up to 100MB (from 10MB).
– Lasoty
Dec 1 '16 at 12:35
That doesn´t mean it´s not released. Garbage collection is undeterminstic, you can´t say when it´s finished andf thus when your memory is relased, only that it happens. Anyway: how did you determine it uses 100MB? Don´t trust TaskManager too much when it comes to Memory.
– HimBromBeere
Dec 1 '16 at 12:37
1
code looks fine to me, but you can read more here: stackoverflow.com/questions/7524903/…
– Thomas Koelle
Dec 1 '16 at 12:40
3
3
Why have you decided this method has memory leak? What makes you think so?
– Andy Korneyev
Dec 1 '16 at 12:26
Why have you decided this method has memory leak? What makes you think so?
– Andy Korneyev
Dec 1 '16 at 12:26
1
1
Can´t see anything here that can´t be handled by GC when leaving the method. So why do you think there is a memory-leak?
– HimBromBeere
Dec 1 '16 at 12:31
Can´t see anything here that can´t be handled by GC when leaving the method. So why do you think there is a memory-leak?
– HimBromBeere
Dec 1 '16 at 12:31
Because when I used this method to serialize one object 10 000 times, memory used by program up to 100MB (from 10MB).
– Lasoty
Dec 1 '16 at 12:35
Because when I used this method to serialize one object 10 000 times, memory used by program up to 100MB (from 10MB).
– Lasoty
Dec 1 '16 at 12:35
That doesn´t mean it´s not released. Garbage collection is undeterminstic, you can´t say when it´s finished andf thus when your memory is relased, only that it happens. Anyway: how did you determine it uses 100MB? Don´t trust TaskManager too much when it comes to Memory.
– HimBromBeere
Dec 1 '16 at 12:37
That doesn´t mean it´s not released. Garbage collection is undeterminstic, you can´t say when it´s finished andf thus when your memory is relased, only that it happens. Anyway: how did you determine it uses 100MB? Don´t trust TaskManager too much when it comes to Memory.
– HimBromBeere
Dec 1 '16 at 12:37
1
1
code looks fine to me, but you can read more here: stackoverflow.com/questions/7524903/…
– Thomas Koelle
Dec 1 '16 at 12:40
code looks fine to me, but you can read more here: stackoverflow.com/questions/7524903/…
– Thomas Koelle
Dec 1 '16 at 12:40
|
show 6 more comments
2 Answers
2
active
oldest
votes
The problem is with a leak in XMLSerializer and it is an official behavior by design.
MS Documenation on XMLSerializer
Dynamically Generated Assemblies
To increase performance, the XML
serialization infrastructure dynamically generates assemblies to
serialize and deserialize specified types. The infrastructure finds
and reuses those assemblies. This behavior occurs only when using the
following constructors:
XmlSerializer.XmlSerializer(Type)
XmlSerializer.XmlSerializer(Type, String)
If you use any of the other
constructors, multiple versions of the same assembly are generated and
never unloaded, which results in a memory leak and poor performance.
The easiest solution is to use one of the previously mentioned two
constructors. Otherwise, you must cache the assemblies in a Hashtable,
as shown in the following example
And read more here on SO for XmlSerializer.FromTypes:
XmlSerializer.FromTypes producing memory leaks?
add a comment |
You should release the resources from the memory by using Dispose() method because C# garbage collector doesn't do that to any object has Dispose() method.
public static string XmlSerialize<T>(T data)
string result;
using (StringWriter stringWriter = new StringWriter())
XmlWriterSettings settings = new XmlWriterSettings
Encoding = Encoding.UTF8,
OmitXmlDeclaration = true,
;
using (XmlWriter writer = XmlWriter.Create(stringWriter, settings))
XmlSerializerNamespaces ns = new XmlSerializerNamespaces();
ns.Add("", "");
XmlSerializer serializer = XmlSerializer.FromTypes(new[] typeof(T) )[0];
serializer.Serialize(writer, data, ns);
if (writer != null)
writer.Dispose();
result = stringWriter.ToString();
if (stringWriter != null)
stringWriter.Dispose();
return result;
Could it be that the use of "USING" this does not settle?
– Lasoty
Dec 1 '16 at 14:11
1
At the end of "using" block Dispose will be called automatically.
– Mateusz
Dec 1 '16 at 14:18
1
This is incorrect, a using block will callDispose
on the object when it leaves scope. It is also considered safer as it will generally callDispose
even if an exception is thrown.
– TheLethalCoder
Dec 1 '16 at 16:31
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f40910617%2fwhere-is-memory-leak-serialize-object%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
The problem is with a leak in XMLSerializer and it is an official behavior by design.
MS Documenation on XMLSerializer
Dynamically Generated Assemblies
To increase performance, the XML
serialization infrastructure dynamically generates assemblies to
serialize and deserialize specified types. The infrastructure finds
and reuses those assemblies. This behavior occurs only when using the
following constructors:
XmlSerializer.XmlSerializer(Type)
XmlSerializer.XmlSerializer(Type, String)
If you use any of the other
constructors, multiple versions of the same assembly are generated and
never unloaded, which results in a memory leak and poor performance.
The easiest solution is to use one of the previously mentioned two
constructors. Otherwise, you must cache the assemblies in a Hashtable,
as shown in the following example
And read more here on SO for XmlSerializer.FromTypes:
XmlSerializer.FromTypes producing memory leaks?
add a comment |
The problem is with a leak in XMLSerializer and it is an official behavior by design.
MS Documenation on XMLSerializer
Dynamically Generated Assemblies
To increase performance, the XML
serialization infrastructure dynamically generates assemblies to
serialize and deserialize specified types. The infrastructure finds
and reuses those assemblies. This behavior occurs only when using the
following constructors:
XmlSerializer.XmlSerializer(Type)
XmlSerializer.XmlSerializer(Type, String)
If you use any of the other
constructors, multiple versions of the same assembly are generated and
never unloaded, which results in a memory leak and poor performance.
The easiest solution is to use one of the previously mentioned two
constructors. Otherwise, you must cache the assemblies in a Hashtable,
as shown in the following example
And read more here on SO for XmlSerializer.FromTypes:
XmlSerializer.FromTypes producing memory leaks?
add a comment |
The problem is with a leak in XMLSerializer and it is an official behavior by design.
MS Documenation on XMLSerializer
Dynamically Generated Assemblies
To increase performance, the XML
serialization infrastructure dynamically generates assemblies to
serialize and deserialize specified types. The infrastructure finds
and reuses those assemblies. This behavior occurs only when using the
following constructors:
XmlSerializer.XmlSerializer(Type)
XmlSerializer.XmlSerializer(Type, String)
If you use any of the other
constructors, multiple versions of the same assembly are generated and
never unloaded, which results in a memory leak and poor performance.
The easiest solution is to use one of the previously mentioned two
constructors. Otherwise, you must cache the assemblies in a Hashtable,
as shown in the following example
And read more here on SO for XmlSerializer.FromTypes:
XmlSerializer.FromTypes producing memory leaks?
The problem is with a leak in XMLSerializer and it is an official behavior by design.
MS Documenation on XMLSerializer
Dynamically Generated Assemblies
To increase performance, the XML
serialization infrastructure dynamically generates assemblies to
serialize and deserialize specified types. The infrastructure finds
and reuses those assemblies. This behavior occurs only when using the
following constructors:
XmlSerializer.XmlSerializer(Type)
XmlSerializer.XmlSerializer(Type, String)
If you use any of the other
constructors, multiple versions of the same assembly are generated and
never unloaded, which results in a memory leak and poor performance.
The easiest solution is to use one of the previously mentioned two
constructors. Otherwise, you must cache the assemblies in a Hashtable,
as shown in the following example
And read more here on SO for XmlSerializer.FromTypes:
XmlSerializer.FromTypes producing memory leaks?
answered Mar 7 at 7:40
hB0hB0
1,4912031
1,4912031
add a comment |
add a comment |
You should release the resources from the memory by using Dispose() method because C# garbage collector doesn't do that to any object has Dispose() method.
public static string XmlSerialize<T>(T data)
string result;
using (StringWriter stringWriter = new StringWriter())
XmlWriterSettings settings = new XmlWriterSettings
Encoding = Encoding.UTF8,
OmitXmlDeclaration = true,
;
using (XmlWriter writer = XmlWriter.Create(stringWriter, settings))
XmlSerializerNamespaces ns = new XmlSerializerNamespaces();
ns.Add("", "");
XmlSerializer serializer = XmlSerializer.FromTypes(new[] typeof(T) )[0];
serializer.Serialize(writer, data, ns);
if (writer != null)
writer.Dispose();
result = stringWriter.ToString();
if (stringWriter != null)
stringWriter.Dispose();
return result;
Could it be that the use of "USING" this does not settle?
– Lasoty
Dec 1 '16 at 14:11
1
At the end of "using" block Dispose will be called automatically.
– Mateusz
Dec 1 '16 at 14:18
1
This is incorrect, a using block will callDispose
on the object when it leaves scope. It is also considered safer as it will generally callDispose
even if an exception is thrown.
– TheLethalCoder
Dec 1 '16 at 16:31
add a comment |
You should release the resources from the memory by using Dispose() method because C# garbage collector doesn't do that to any object has Dispose() method.
public static string XmlSerialize<T>(T data)
string result;
using (StringWriter stringWriter = new StringWriter())
XmlWriterSettings settings = new XmlWriterSettings
Encoding = Encoding.UTF8,
OmitXmlDeclaration = true,
;
using (XmlWriter writer = XmlWriter.Create(stringWriter, settings))
XmlSerializerNamespaces ns = new XmlSerializerNamespaces();
ns.Add("", "");
XmlSerializer serializer = XmlSerializer.FromTypes(new[] typeof(T) )[0];
serializer.Serialize(writer, data, ns);
if (writer != null)
writer.Dispose();
result = stringWriter.ToString();
if (stringWriter != null)
stringWriter.Dispose();
return result;
Could it be that the use of "USING" this does not settle?
– Lasoty
Dec 1 '16 at 14:11
1
At the end of "using" block Dispose will be called automatically.
– Mateusz
Dec 1 '16 at 14:18
1
This is incorrect, a using block will callDispose
on the object when it leaves scope. It is also considered safer as it will generally callDispose
even if an exception is thrown.
– TheLethalCoder
Dec 1 '16 at 16:31
add a comment |
You should release the resources from the memory by using Dispose() method because C# garbage collector doesn't do that to any object has Dispose() method.
public static string XmlSerialize<T>(T data)
string result;
using (StringWriter stringWriter = new StringWriter())
XmlWriterSettings settings = new XmlWriterSettings
Encoding = Encoding.UTF8,
OmitXmlDeclaration = true,
;
using (XmlWriter writer = XmlWriter.Create(stringWriter, settings))
XmlSerializerNamespaces ns = new XmlSerializerNamespaces();
ns.Add("", "");
XmlSerializer serializer = XmlSerializer.FromTypes(new[] typeof(T) )[0];
serializer.Serialize(writer, data, ns);
if (writer != null)
writer.Dispose();
result = stringWriter.ToString();
if (stringWriter != null)
stringWriter.Dispose();
return result;
You should release the resources from the memory by using Dispose() method because C# garbage collector doesn't do that to any object has Dispose() method.
public static string XmlSerialize<T>(T data)
string result;
using (StringWriter stringWriter = new StringWriter())
XmlWriterSettings settings = new XmlWriterSettings
Encoding = Encoding.UTF8,
OmitXmlDeclaration = true,
;
using (XmlWriter writer = XmlWriter.Create(stringWriter, settings))
XmlSerializerNamespaces ns = new XmlSerializerNamespaces();
ns.Add("", "");
XmlSerializer serializer = XmlSerializer.FromTypes(new[] typeof(T) )[0];
serializer.Serialize(writer, data, ns);
if (writer != null)
writer.Dispose();
result = stringWriter.ToString();
if (stringWriter != null)
stringWriter.Dispose();
return result;
answered Dec 1 '16 at 13:58
M.SarminiM.Sarmini
703
703
Could it be that the use of "USING" this does not settle?
– Lasoty
Dec 1 '16 at 14:11
1
At the end of "using" block Dispose will be called automatically.
– Mateusz
Dec 1 '16 at 14:18
1
This is incorrect, a using block will callDispose
on the object when it leaves scope. It is also considered safer as it will generally callDispose
even if an exception is thrown.
– TheLethalCoder
Dec 1 '16 at 16:31
add a comment |
Could it be that the use of "USING" this does not settle?
– Lasoty
Dec 1 '16 at 14:11
1
At the end of "using" block Dispose will be called automatically.
– Mateusz
Dec 1 '16 at 14:18
1
This is incorrect, a using block will callDispose
on the object when it leaves scope. It is also considered safer as it will generally callDispose
even if an exception is thrown.
– TheLethalCoder
Dec 1 '16 at 16:31
Could it be that the use of "USING" this does not settle?
– Lasoty
Dec 1 '16 at 14:11
Could it be that the use of "USING" this does not settle?
– Lasoty
Dec 1 '16 at 14:11
1
1
At the end of "using" block Dispose will be called automatically.
– Mateusz
Dec 1 '16 at 14:18
At the end of "using" block Dispose will be called automatically.
– Mateusz
Dec 1 '16 at 14:18
1
1
This is incorrect, a using block will call
Dispose
on the object when it leaves scope. It is also considered safer as it will generally call Dispose
even if an exception is thrown.– TheLethalCoder
Dec 1 '16 at 16:31
This is incorrect, a using block will call
Dispose
on the object when it leaves scope. It is also considered safer as it will generally call Dispose
even if an exception is thrown.– TheLethalCoder
Dec 1 '16 at 16:31
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f40910617%2fwhere-is-memory-leak-serialize-object%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
3
Why have you decided this method has memory leak? What makes you think so?
– Andy Korneyev
Dec 1 '16 at 12:26
1
Can´t see anything here that can´t be handled by GC when leaving the method. So why do you think there is a memory-leak?
– HimBromBeere
Dec 1 '16 at 12:31
Because when I used this method to serialize one object 10 000 times, memory used by program up to 100MB (from 10MB).
– Lasoty
Dec 1 '16 at 12:35
That doesn´t mean it´s not released. Garbage collection is undeterminstic, you can´t say when it´s finished andf thus when your memory is relased, only that it happens. Anyway: how did you determine it uses 100MB? Don´t trust TaskManager too much when it comes to Memory.
– HimBromBeere
Dec 1 '16 at 12:37
1
code looks fine to me, but you can read more here: stackoverflow.com/questions/7524903/…
– Thomas Koelle
Dec 1 '16 at 12:40