DirectoryInfo dir = new DirectoryInfo(mydir);
foreach (FileInfo f in dir.GetFiles("*.std"))
{
// Create a filestream for our new file.
FileStream fs = s.file_open(f.FullName); // calls a simple method that opens a filestream object.
// Determine the length of the filestream, and create the appropriate variables.
double tmp_length = fs.Length;
int length = (int)tmp_length;
byte[] byteArray = new byte[0];
string PART_TYP = null;
byteArray = new byte[length];
fs.Read(byteArray, 0, length);
fs.Close();
for (int j=0; j<byteArray.Length; j++)
{
// Go do some stuff with this binary data...
}
}
So, my question is, after my for loop, how do I "clean up" the byteArray array. I've tried calling GC.Collect() and that has no effect. After a couple of files, VS throws an out of memory error and because the process is using all the RAM.
This is probably a really easy question, I've just never dealt with memory allocation before.
Any help would be VERY VERY much appreciated as I have been struggling with this for quite a while.
Thanks a lot!
AnttiRank #9,295 · 208 pointsPosted Dec 8, 2005, 8:40 AM EST
byteArray = null;Usually you should check if a class implements IDisposable interface; when class does that, it has Dispose-method that enables eplicit object disposion (not the case with Array class).
        //is "disposion" even a word?;)
tylerstaszak3 pointsPosted Dec 8, 2005, 9:05 AM EST
AnttiRank #9,295 · 208 pointsPosted Dec 8, 2005, 9:47 PM EST
twistedJP2 pointsPosted Dec 13, 2005, 8:27 PM EST
I do this when killing the array;
ByteArray = new Byte[]{};
ByteArray = null;
Just a suggestion.
Larry
AnttiRank #9,295 · 208 pointsPosted Dec 13, 2005, 8:32 PM EST