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













1















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?










share|improve this question



















  • 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















1















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?










share|improve this question



















  • 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













1












1








1








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?










share|improve this question
















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






share|improve this question















share|improve this question













share|improve this question




share|improve this question








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












  • 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












2 Answers
2






active

oldest

votes


















0














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?






share|improve this answer






























    -1














    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;






    share|improve this answer























    • 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 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










    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
    );



    );













    draft saved

    draft discarded


















    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









    0














    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?






    share|improve this answer



























      0














      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?






      share|improve this answer

























        0












        0








        0







        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?






        share|improve this answer













        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?







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Mar 7 at 7:40









        hB0hB0

        1,4912031




        1,4912031























            -1














            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;






            share|improve this answer























            • 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 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















            -1














            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;






            share|improve this answer























            • 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 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













            -1












            -1








            -1







            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;






            share|improve this answer













            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;







            share|improve this answer












            share|improve this answer



            share|improve this answer










            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 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

















            • 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 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
















            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

















            draft saved

            draft discarded
















































            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.




            draft saved


            draft discarded














            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





















































            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







            Popular posts from this blog

            Save data to MySQL database using ExtJS and PHP [closed]2019 Community Moderator ElectionHow can I prevent SQL injection in PHP?Which MySQL data type to use for storing boolean valuesPHP: Delete an element from an arrayHow do I connect to a MySQL Database in Python?Should I use the datetime or timestamp data type in MySQL?How to get a list of MySQL user accountsHow Do You Parse and Process HTML/XML in PHP?Reference — What does this symbol mean in PHP?How does PHP 'foreach' actually work?Why shouldn't I use mysql_* functions in PHP?

            Compiling GNU Global with universal-ctags support Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern) Data science time! April 2019 and salary with experience The Ask Question Wizard is Live!Tags for Emacs: Relationship between etags, ebrowse, cscope, GNU Global and exuberant ctagsVim and Ctags tips and trickscscope or ctags why choose one over the other?scons and ctagsctags cannot open option file “.ctags”Adding tag scopes in universal-ctagsShould I use Universal-ctags?Universal ctags on WindowsHow do I install GNU Global with universal ctags support using Homebrew?Universal ctags with emacsHow to highlight ctags generated by Universal Ctags in Vim?

            Add ONERROR event to image from jsp tldHow to add an image to a JPanel?Saving image from PHP URLHTML img scalingCheck if an image is loaded (no errors) with jQueryHow to force an <img> to take up width, even if the image is not loadedHow do I populate hidden form field with a value set in Spring ControllerStyling Raw elements Generated from JSP tagds with Jquery MobileLimit resizing of images with explicitly set width and height attributeserror TLD use in a jsp fileJsp tld files cannot be resolved