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