Garbage Collector Data Table

  • Thread starter Thread starter Priya Bange
  • Start date Start date
P

Priya Bange

Guest
Hi Experts,

I have the following code that reads a special xml file format generated via SQL Server. The code runs absolutely fine and is scheduled to run as a service but when run its not freeing the memory once the file get processed as checked from the task manager memory.. The memory increases same as the size of file and stays intact.

I have used the dispose & set to null.

Please advise how can I get the rid of the memory from the data table once finished execution. Am trying the released version as a service. Am also a newbie in C# so please guide.


using Microsoft.SqlServer.XEvent.Linq;
using System;
using System.Data;
using System.Data.SqlClient;



public static void QueryPerfReadXeFile(String InputFilePath)
{

var dt = new DataTable();
dt.Columns.Add("Event_Name", typeof(string));
dt.Columns.Add("object_name", typeof(string));
dt.Columns.Add("object_id", typeof(Int32));
dt.Columns.Add("object_type", typeof(string));



using (var events = new QueryableXEventData(InputFilePath))
{
foreach (var xe in events)
{
var row = dt.NewRow();
dt.Rows.Add(row);
row["Event_Name"] = xe.Name;

xe.Fields.TryGetValue("object_id", out PublishedEventField object_id);
row["object_id"] = object_id == null ? 0 : object_id.Value;

xe.Fields.TryGetValue("object_name", out PublishedEventField object_name);
row["object_name"] = object_name == null ? 0 : object_name.Value;



xe.Fields.TryGetValue("object_type", out PublishedEventField object_type);
row["object_type"] = object_type?.Value;


}


}



dt.Dispose();
dt = null;

}


Thanks

Priya

Continue reading...
 
Back
Top