473,388 Members | 1,526 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,388 software developers and data experts.

I can reproduce this Memory leak!

This is possible memory leak can be reproduced by the
following code. I am hoping someone can help me out with
simple solutions! Thanks in advanced!

using System;
using System.IO;
using System.Xml;
using System.Xml.Schema;
using System.Xml.XPath;
using System.Xml.Xsl;
using System.Text;
using System.Security.Policy;
using System.Reflection;

namespace MemoryLeak
{
/// <summary>
/// Summary description for Class1.
/// </summary>
class MemoryLeak
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main(string[] args)
{
//
// TODO: Add code to start application here
//
string str=null;
MemoryLeak memLeak = new MemoryLeak();
try
{
string strXml, strXslt;
strXml = memLeak.ReadWholeFile(args[0]);
strXslt = memLeak.ReadWholeFile(args[1]);
str = memLeak.TranslateXMLContent(strXml, strXslt);
}

catch (Exception e)
{
Console.WriteLine("catch..."+e.Message);
}

finally
{
Console.WriteLine(str);
}
Console.ReadLine();
}

public MemoryLeak()
{

}

public string ReadWholeFile(string fileName)
{
StreamReader sr;
char[] buffer;
int ret;

sr = new StreamReader(fileName);
buffer = new char[sr.BaseStream.Length];
ret = sr.Read(buffer, 0, (int)sr.BaseStream.Length);
sr.Close();
return new String(buffer);
}

public string TranslateXMLContent(string strXml, string
strXslt)
{
string str = null;
XmlTextReader myXsltReader = null;
XmlTextReader myXmlReader = null;
StringBuilder myStringBuilder = null;
StringWriter myStringWriter = null;
XmlTextWriter myXmlWriter = null;
Evidence evd;

//Create the XslTransform and load the stylesheet.
XslTransform xslt = new XslTransform();
try
{
evd = Assembly.GetCallingAssembly().Evidence;
myXsltReader = new XmlTextReader(new StringReader
(strXslt));
//urlResolver.Credentials =
CredentialCache.DefaultCredentials;
xslt.Load(myXsltReader, null, evd);

//Load the XML data file.
myXmlReader = new XmlTextReader(new StringReader
(strXml));
XPathDocument doc = new XPathDocument(myXmlReader);
//Add an object to convert the book price.
myStringBuilder = new StringBuilder();
myStringWriter = new StringWriter(myStringBuilder);
myXmlWriter = new XmlTextWriter(myStringWriter);
xslt.Transform(doc, null, myXmlWriter, null);

//Transform.
str = myStringBuilder.ToString();
}

catch (Exception e)
{
Console.WriteLine(e.Message);
throw e;
}

finally
{
if (myXsltReader != null)
myXsltReader.Close();
if (myXmlReader != null)
myXmlReader.Close();
if (myStringWriter!= null)
myStringWriter.Close();
}
return str;
}
}
}
xsl file :
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:msxsl="urn:schemas-microsoft-com:xslt"
xmlns:nqxsl="urn:netquote-com:xslt">
<msxsl:script language="CSharp" implements-prefix="nqxsl">
<![CDATA[
public string UpperCase(string str) {
return str.ToUpper();
}
]]>
</msxsl:script>
<xsl:output method="xml" indent="no" />
<xsl:template match="/">
<xsl:value-of select="nqxsl:UpperCase(.)"/>
</xsl:template>
</xsl:stylesheet>

sample xml file:
<?xml version="1.0" encoding="UTF-8"?>
<xmlRoot>test for memory leak</xmlRoot>

There is always one Evidence Class that has a strong handle
(using windbg.exe). I know this is cased by the C# code in
the xsl file. If you take the C# out everything works
fine.

I am wonder does anybody know how to solve this issue for
me? My program converts hunderds of this kind file
everyday and it causes big memory leak. I know the
extension obj will work fine but I don't want to go that
rounte at this poing.

Many thanks
Qin Zhou
Jul 19 '05 #1
5 4779
Hi Qin,

I will have a try and get back to you as soon as I have any findings.

Sincerely,
Xiao Xie
Microsoft Developer Support

This posting is provided "AS IS" with no warranties, and confers no rights.

Jul 19 '05 #2
Thanks very much!

Sincerely,
Qin Zhou
-----Original Message-----
Hi Qin,

I will have a try and get back to you as soon as I have any findings.
Sincerely,
Xiao Xie
Microsoft Developer Support

This posting is provided "AS IS" with no warranties, and confers no rights.
.

Jul 19 '05 #3
Hi Qin,

Sorry for the late update.

I tried the program and added a loop for the XSL translation to repeat
infinitely. At first I also observed the memory usage curves to keep
climbing. However, after several minutes of execution, the memory usage
curves become stable and evetually stayed at 4,008 KB for Private Bytes
(the VM Size column in Task Manager). So it still seemed to be a caching
facility and no real leak happened. Did you see the same behavior?

I tried it on .NET Framework v1.1/Windows XP SP1.

Sincerely,
Xiao Xie
Microsoft Developer Support

This posting is provided "AS IS" with no warranties, and confers no rights.

Jul 19 '05 #4
Xiao Xie,

Thanks for your reply. I used windbg.exe and did a memory
dump. For those xslt file that uses c# code you will see
there is an Evidence Object has a "Strong Handle"
associates with it(I didn't do a loop, but I am not sure
loop will do because they might cache the c# code for
certain time). And those that don't have c# code do not
have any strong handle associates with it. Does this make
sense? If you want, please feel free to contact me
directly at my email address and I can send you my phone#.

Again

Thanks very much

Qin Zhou
-----Original Message-----
Hi Qin,

Sorry for the late update.

I tried the program and added a loop for the XSL translation to repeatinfinitely. At first I also observed the memory usage curves to keepclimbing. However, after several minutes of execution, the memory usagecurves become stable and evetually stayed at 4,008 KB for Private Bytes(the VM Size column in Task Manager). So it still seemed to be a cachingfacility and no real leak happened. Did you see the same behavior?
I tried it on .NET Framework v1.1/Windows XP SP1.

Sincerely,
Xiao Xie
Microsoft Developer Support

This posting is provided "AS IS" with no warranties, and confers no rights.
.

Jul 19 '05 #5
Hi Qin,

Oh yes, I believe I can repro it now. I will get back to you with my
findings.

Thanks.

Sincerely,
Xiao Xie
Microsoft Developer Support

This posting is provided "AS IS" with no warranties, and confers no rights.

Jul 19 '05 #6

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

Similar topics

8
by: Qin Zhou | last post by:
This is possible memory leak can be reproduced by the following code. I am hoping someone can help me out with simple solutions! Thanks in advanced! using System; using System.IO; using...
8
by: ranjeet.gupta | last post by:
Dear All Is the Root Cause of the Memory corruption is the Memory leak, ?? suppose If in the code there is Memory leak, Do this may lead to the Memory Corruption while executing the program ? ...
4
by: Don Nell | last post by:
Hello Why is there a memory leak when this code is executed. for(;;) { ManagementScope scope = new ManagementScope(); scope.Options.Username="username"; scope.Options.Password="password";...
20
by: jeevankodali | last post by:
Hi I have an .Net application which processes thousands of Xml nodes each day and for each node I am using around 30-40 Regex matches to see if they satisfy some conditions are not. These Regex...
23
by: James | last post by:
The following code will create memory leaks!!! using System; using System.Diagnostics; using System.Data; using System.Data.SqlClient; namespace MemoryLeak
8
by: Adrian | last post by:
Hi I have a JS program that runs localy (under IE6 only) on a PC but it has a memory leak (probably the known MS one!) What applications are there that I could use to look at the memory usage of...
3
by: Jim Land | last post by:
Jack Slocum claims here http://www.jackslocum.com/yui/2006/10/02/3-easy-steps-to-avoid-javascript- memory-leaks/ that "almost every site you visit that uses JavaScript is leaking memory". ...
7
by: Ragnar Agustsson | last post by:
Hi all I have been wandering about the best way to sandbox memory leaks in 3rd party libraries when using them from the .Net framework. I have a 3rd party library, written in C++, that leaks a...
22
by: Peter | last post by:
I am using VS2008. I have a Windows Service application which creates Crystal Reports. This is a multi theaded application which can run several reports at one time. My problem - there is a...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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...

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.