Is DataSet.GetXml leaking memory?

  • Thread starter Thread starter Sunil Menon
  • Start date Start date
S

Sunil Menon

Dear All,
I was just browsing through my code checking where my application is
allocating memory and found that my code frequently calls
Dataset.GetXml to get xml string output to store data in database.
Further investigation through .Net reflector revealed that the call
creates a stringwriter that it never disposes. Is this a possible
memory leak?
Should the code be using the <using> call when calling a disposable
object?
The following is the code snag-it:
public string GetXml()
{
string text1;
IntPtr ptr1;
Bid.ScopeEnter(out ptr1, "<ds.DataSet.GetXml|API> %d#\n",
this.ObjectID);
try
{
StringWriter writer1 = new
StringWriter(CultureInfo.InvariantCulture);
if (writer1 != null)
{
XmlTextWriter writer2 = new XmlTextWriter(writer1);
writer2.Formatting = Formatting.Indented;
new XmlDataTreeWriter(this).Save(writer2, false);
}
text1 = writer1.ToString();
}
finally
{
Bid.ScopeLeave(ref ptr1);
}
return text1;
}


Please help.

Thanks & regards
Sunil
 
StringWriter is very probably not leaking memory. IOW you don't need to
dispose it though it is a good practice to do so.
 
StringWriter is very probably not leakingmemory. IOW you don't need to
dispose it though it is a good practice to do so.

--
Miha Markic [MVP C#, INETA Country Leader for Slovenia]
RightHand .NET consulting & developmentwww.rthand.com
Blog:http://cs.rthand.com/blogs/blog_with_righthand/


Dear All,
I was just browsing through my code checking where my application is
allocatingmemoryand found that my code frequently calls
Dataset.GetXmlto get xml string output to store data in database.
Further investigation through .Net reflector revealed that the call
creates a stringwriter that it never disposes. Is this a possible
memoryleak?
Should the code be using the <using> call when calling a disposable
object?
The following is the code snag-it:
public string GetXml()
{
string text1;
IntPtr ptr1;
Bid.ScopeEnter(outptr1, "<ds.DataSet.GetXml|API> %d#\n",
this.ObjectID);
try
{
StringWriter writer1 = new
StringWriter(CultureInfo.InvariantCulture);
if (writer1 != null)
{
XmlTextWriter writer2 = new XmlTextWriter(writer1);
writer2.Formatting = Formatting.Indented;
new XmlDataTreeWriter(this).Save(writer2, false);
}
text1 = writer1.ToString();
}
finally
{
Bid.ScopeLeave(ref ptr1);
}
return text1;
}
Please help.
Thanks & regards
Sunil

I have the same problem using getxml() method. Please tell me how can
I solve it...is there any solution?
 
Back
Top