|
-
May 4th, 2006, 06:50 AM
#22
Thread Starter
Fanatic Member
Re: Memory Leak Question
Thanks I will look at the articles. This discussion has helped me a lot, albeit a pain in the backside. Yes, all of my memory readings are from the task manager. I did find out that the framework keeps a working set of memory, which may be noted in your articles. In addition, even though my app is not using memory .net still holds onto it in memory. This article was helpful.
This much simplified code demonstrates the fact, that prior to my program removing any working sets it is using 564MB of memory. After I reduce the working sets to zero the memory used is 1.3MB, again all reported from Task Manager.
Code:
class Class1
{
[STAThread]
[DllImport("kernel32")]
static extern bool SetProcessWorkingSetSize(IntPtr handle, int minSize, int maxSize);
static void Main(string[] args)
{
Class1 tempclass = new Class1();
tempclass.SortFile(@"c:\tmp\Really Big File.txt", @"c:\tmp\Really Big File Sorted.txt");
tempclass = null;
SetProcessWorkingSetSize(Process.GetCurrentProcess().Handle, -1, -1);
}
private void SortFile(string inputFilePath, string outputFilePath)
{
string[] fileArray = null;
using (System.IO.StreamReader sr = new System.IO.StreamReader(inputFilePath))
{
fileArray = System.Text.RegularExpressions.Regex.Split(sr.ReadToEnd(), Environment.NewLine);
sr.Close();
}
Array.Sort(fileArray);
using (System.IO.StreamWriter sw = new System.IO.StreamWriter(outputFilePath))
{
foreach (string inputLine in fileArray)
{
sw.WriteLine(inputLine);
}
sw.Close();
}
fileArray = null;
}
}
Last edited by steve65; May 4th, 2006 at 07:11 AM.
This space for rent...
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|