473,396 Members | 1,775 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

XmlDataDocument\DataSet Memory Footprint, Feedback appreciated.

I am reading in xml files that equate to sql tables, via XmlDataDocument,
and then operating on the DataSet. With the most simple app that just loads
the xml doc, I see the memory footprint of the app grow to roughly 5x the
size of the xml document after the xml doc is read. Can anyone comment on
this? Is this expected?

Below are two samples, the first hits northwind, and creates a 19meg
(roughly, on my machine) xml file. The second simply reads it in, with a
pause after reading so you can inspect the memory usage in task manager.

Any suggestions as to how I can get the footprint down much closer to the
size of the xml file would be greatly appreciated.

Thanks in advance!!

Derrick


Creation of sample xml file:
using System;
using System.Data;
using System.Data.SqlClient;
using System.Xml;
namespace DataExtract
{
class Class1
{
[STAThread]
static void Main(string[] args)
{
string forXml = " FOR XML AUTO, XMLDATA";
SqlConnection mySqlConnection = new
SqlConnection("server=127.0.0.1;database=northwind ;uid=sa;pwd=admin");
XmlTextReader myXmlReader = null;
SqlCommand mySqlCmd = new SqlCommand();
DataSet myDataSet = new DataSet();
mySqlConnection.Open();
mySqlCmd.Connection = mySqlConnection;
mySqlCmd.CommandText = "select * from orders cross join customers" + forXml;
myXmlReader = (XmlTextReader)mySqlCmd.ExecuteXmlReader();
myDataSet.ReadXml(myXmlReader, XmlReadMode.Fragment);
myXmlReader.Close();
myDataSet.WriteXml("c:\\lotsa_data.xml");
myDataSet.WriteXmlSchema("c:\\lotsa_data.xsd");
myDataSet.Dispose();
mySqlConnection.Close();
}
}
}

The reader:

using System.Data;
using System.Xml;
using System.IO;
namespace DataRead
{
class Class1
{
[STAThread]
static void Main(string[] args)
{
Stream xsdStream = new StreamReader("c:\\lotsa_data.xsd").BaseStream;
Stream xmlStream = new StreamReader("c:\\lotsa_data.xml").BaseStream;
XmlDataDocument myXmlDoc = new XmlDataDocument();
myXmlDoc.DataSet.ReadXmlSchema(xsdStream);
myXmlDoc.Load(xmlStream);
Console.WriteLine("Loaded...");
Console.ReadLine();
}
}
}
Nov 15 '05 #1
3 2137
Hello

I suggest you use a memory profiler to track where your memory is consumed.
Here is a good one
http://www.scitech.se/memprofiler/
This software tells you the datatypes of allocated objects

Best regards
Sherif

"Derrick" <de*********@excite.com> wrote in message
news:Oo*************@tk2msftngp13.phx.gbl...
I am reading in xml files that equate to sql tables, via XmlDataDocument,
and then operating on the DataSet. With the most simple app that just loads the xml doc, I see the memory footprint of the app grow to roughly 5x the
size of the xml document after the xml doc is read. Can anyone comment on
this? Is this expected?

Below are two samples, the first hits northwind, and creates a 19meg
(roughly, on my machine) xml file. The second simply reads it in, with a
pause after reading so you can inspect the memory usage in task manager.

Any suggestions as to how I can get the footprint down much closer to the
size of the xml file would be greatly appreciated.

Thanks in advance!!

Derrick


Creation of sample xml file:
using System;
using System.Data;
using System.Data.SqlClient;
using System.Xml;
namespace DataExtract
{
class Class1
{
[STAThread]
static void Main(string[] args)
{
string forXml = " FOR XML AUTO, XMLDATA";
SqlConnection mySqlConnection = new
SqlConnection("server=127.0.0.1;database=northwind ;uid=sa;pwd=admin");
XmlTextReader myXmlReader = null;
SqlCommand mySqlCmd = new SqlCommand();
DataSet myDataSet = new DataSet();
mySqlConnection.Open();
mySqlCmd.Connection = mySqlConnection;
mySqlCmd.CommandText = "select * from orders cross join customers" + forXml; myXmlReader = (XmlTextReader)mySqlCmd.ExecuteXmlReader();
myDataSet.ReadXml(myXmlReader, XmlReadMode.Fragment);
myXmlReader.Close();
myDataSet.WriteXml("c:\\lotsa_data.xml");
myDataSet.WriteXmlSchema("c:\\lotsa_data.xsd");
myDataSet.Dispose();
mySqlConnection.Close();
}
}
}

The reader:

using System.Data;
using System.Xml;
using System.IO;
namespace DataRead
{
class Class1
{
[STAThread]
static void Main(string[] args)
{
Stream xsdStream = new StreamReader("c:\\lotsa_data.xsd").BaseStream;
Stream xmlStream = new StreamReader("c:\\lotsa_data.xml").BaseStream;
XmlDataDocument myXmlDoc = new XmlDataDocument();
myXmlDoc.DataSet.ReadXmlSchema(xsdStream);
myXmlDoc.Load(xmlStream);
Console.WriteLine("Loaded...");
Console.ReadLine();
}
}
}

Nov 15 '05 #2
Thanks, downloaded and tried it out, it basically looks like XML objects
(elements and attributes) are half the bag, strings the other half. Is
there a way to read in the XML as simple data, toss the xml associated
objects out, and end up with just native types in the DataSet tables?

The code that reads the xml file into a dataset is all core C#...

Thanks again!
"Sherif ElMetainy" <el*************@wayout.net.NOSPAM> wrote in message
news:%2*****************@TK2MSFTNGP11.phx.gbl...
Hello

I suggest you use a memory profiler to track where your memory is consumed. Here is a good one
http://www.scitech.se/memprofiler/
This software tells you the datatypes of allocated objects

Best regards
Sherif

"Derrick" <de*********@excite.com> wrote in message
news:Oo*************@tk2msftngp13.phx.gbl...
I am reading in xml files that equate to sql tables, via XmlDataDocument, and then operating on the DataSet. With the most simple app that just

loads
the xml doc, I see the memory footprint of the app grow to roughly 5x the size of the xml document after the xml doc is read. Can anyone comment on this? Is this expected?

Below are two samples, the first hits northwind, and creates a 19meg
(roughly, on my machine) xml file. The second simply reads it in, with a pause after reading so you can inspect the memory usage in task manager.

Any suggestions as to how I can get the footprint down much closer to the size of the xml file would be greatly appreciated.

Thanks in advance!!

Derrick


Creation of sample xml file:
using System;
using System.Data;
using System.Data.SqlClient;
using System.Xml;
namespace DataExtract
{
class Class1
{
[STAThread]
static void Main(string[] args)
{
string forXml = " FOR XML AUTO, XMLDATA";
SqlConnection mySqlConnection = new
SqlConnection("server=127.0.0.1;database=northwind ;uid=sa;pwd=admin");
XmlTextReader myXmlReader = null;
SqlCommand mySqlCmd = new SqlCommand();
DataSet myDataSet = new DataSet();
mySqlConnection.Open();
mySqlCmd.Connection = mySqlConnection;
mySqlCmd.CommandText = "select * from orders cross join customers" +

forXml;
myXmlReader = (XmlTextReader)mySqlCmd.ExecuteXmlReader();
myDataSet.ReadXml(myXmlReader, XmlReadMode.Fragment);
myXmlReader.Close();
myDataSet.WriteXml("c:\\lotsa_data.xml");
myDataSet.WriteXmlSchema("c:\\lotsa_data.xsd");
myDataSet.Dispose();
mySqlConnection.Close();
}
}
}

The reader:

using System.Data;
using System.Xml;
using System.IO;
namespace DataRead
{
class Class1
{
[STAThread]
static void Main(string[] args)
{
Stream xsdStream = new StreamReader("c:\\lotsa_data.xsd").BaseStream;
Stream xmlStream = new StreamReader("c:\\lotsa_data.xml").BaseStream;
XmlDataDocument myXmlDoc = new XmlDataDocument();
myXmlDoc.DataSet.ReadXmlSchema(xsdStream);
myXmlDoc.Load(xmlStream);
Console.WriteLine("Loaded...");
Console.ReadLine();
}
}
}


Nov 15 '05 #3
Hello

You can set the references to all xml objects to null, so that they are not
referenced anymore by your code.
Then they will be collected in the next garbage collection.

You can also force garbage collection to run immediately by calling
System.GC.Collect(), but many people thinks its better that you let the CLR
do garbage collection when it wants.

Best regards,
Sherif

"Derrick" <de*********@excite.com> wrote in message
news:eD**************@tk2msftngp13.phx.gbl...
Thanks, downloaded and tried it out, it basically looks like XML objects
(elements and attributes) are half the bag, strings the other half. Is
there a way to read in the XML as simple data, toss the xml associated
objects out, and end up with just native types in the DataSet tables?

The code that reads the xml file into a dataset is all core C#...

Thanks again!
"Sherif ElMetainy" <el*************@wayout.net.NOSPAM> wrote in message
news:%2*****************@TK2MSFTNGP11.phx.gbl...
Hello

I suggest you use a memory profiler to track where your memory is consumed.
Here is a good one
http://www.scitech.se/memprofiler/
This software tells you the datatypes of allocated objects

Best regards
Sherif

"Derrick" <de*********@excite.com> wrote in message
news:Oo*************@tk2msftngp13.phx.gbl...
I am reading in xml files that equate to sql tables, via XmlDataDocument, and then operating on the DataSet. With the most simple app that just

loads
the xml doc, I see the memory footprint of the app grow to roughly 5x the size of the xml document after the xml doc is read. Can anyone comment on
this? Is this expected?

Below are two samples, the first hits northwind, and creates a 19meg
(roughly, on my machine) xml file. The second simply reads it in,
with
a pause after reading so you can inspect the memory usage in task
manager.
Any suggestions as to how I can get the footprint down much closer to

the size of the xml file would be greatly appreciated.

Thanks in advance!!

Derrick


Creation of sample xml file:
using System;
using System.Data;
using System.Data.SqlClient;
using System.Xml;
namespace DataExtract
{
class Class1
{
[STAThread]
static void Main(string[] args)
{
string forXml = " FOR XML AUTO, XMLDATA";
SqlConnection mySqlConnection = new
SqlConnection("server=127.0.0.1;database=northwind ;uid=sa;pwd=admin");
XmlTextReader myXmlReader = null;
SqlCommand mySqlCmd = new SqlCommand();
DataSet myDataSet = new DataSet();
mySqlConnection.Open();
mySqlCmd.Connection = mySqlConnection;
mySqlCmd.CommandText = "select * from orders cross join customers" +

forXml;
myXmlReader = (XmlTextReader)mySqlCmd.ExecuteXmlReader();
myDataSet.ReadXml(myXmlReader, XmlReadMode.Fragment);
myXmlReader.Close();
myDataSet.WriteXml("c:\\lotsa_data.xml");
myDataSet.WriteXmlSchema("c:\\lotsa_data.xsd");
myDataSet.Dispose();
mySqlConnection.Close();
}
}
}

The reader:

using System.Data;
using System.Xml;
using System.IO;
namespace DataRead
{
class Class1
{
[STAThread]
static void Main(string[] args)
{
Stream xsdStream = new StreamReader("c:\\lotsa_data.xsd").BaseStream;
Stream xmlStream = new StreamReader("c:\\lotsa_data.xml").BaseStream;
XmlDataDocument myXmlDoc = new XmlDataDocument();
myXmlDoc.DataSet.ReadXmlSchema(xsdStream);
myXmlDoc.Load(xmlStream);
Console.WriteLine("Loaded...");
Console.ReadLine();
}
}
}



Nov 15 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Mike Peretz | last post by:
I am trying to optimize my C# program, but no matter what I try the application keeps eating memory. I verified all the references and even got special software to count references. I made sure all...
2
by: tomvr | last post by:
Hello I have noticed some 'weird' memory usage in a vb.net windows app The situation is as follows I have an app (heavy on images) with 2 forms (actually there are more forms and on starting...
6
by: Tom | last post by:
We have a VERY simple .NET C# Form Application, that has about a 23MB Memory Footprint. It starts a window runs a process and does a regular expression. I have done a GC.Collect to make sure that,...
2
by: assi | last post by:
Hello all We are developing a large dotnet application, which includes ~ 120 assemblies. (total size of all binaries is ~ 20MB). Our application also references the following dotnet assemblies:...
9
by: Mike P | last post by:
I know everything about reference counting and making sure you don't have large objects lying around. I have also profiled my app with multiple tools. I know about the fact GC collects memory but...
1
by: Derrick | last post by:
Thanks to many on this newsgroup, I now have a prototype Windows Forms C# app that reads xml documents into DataSets via XmlDataDocument, and does *stuff* with it. I basically have about 25 megs...
1
by: Derrick | last post by:
I am reading in xml files that equate to sql tables, via XmlDataDocument, and then operating on the DataSet. With the most simple app that just loads the xml doc, I see the memory footprint of the...
12
by: Varun Kacholia | last post by:
Apologies if this has been answered somewhere, but Google did not produce any concrete results. I would like to find out the memory footprint of a vector<T>. I tried to dig in the STL code and...
9
by: jeungster | last post by:
Hello, I'm trying to track down a memory issue with a C++ application that I'm working on: In a nutshell, the resident memory usage of my program continues to grow as the program runs. It...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.