Hi Again… IanR is correct, I was not getting and “exception” but a message which by all accounts is just a warning explaining that memory compacting is required… OK, accepted and thanks for you input.
I have now added to my project.
I am still having trouble with ReadLine(). I now have several serial ports open, a bunch of interrupts set, two threads, a small database built using ArrayList() and the possibility of two files open at once from the same SD card file system. Before you look below at my trace, yes I look to be using a lot of resources… I agree, but before the call to ReadLine() I appear to have remaining resources, yet I now get a true Out of Memeory Exception.
Here is the Garbage Collector output and the code… The exception occurs as the ReadLine() and I still suspect that the buffer allocated by ReadLine is very large as the thread I originally included above suggests.
GC: 2msec 38832 bytes used, 25548 bytes available
Type 0F (STRING ): 288 bytes
Type 11 (CLASS ): 2592 bytes
Type 12 (VALUETYPE ): 192 bytes
Type 13 (SZARRAY ): 9804 bytes
Type 15 (FREEBLOCK ): 25548 bytes
Type 16 (CACHEDBLOCK ): 192 bytes
Type 17 (ASSEMBLY ): 12396 bytes
Type 18 (WEAKCLASS ): 48 bytes
Type 1B (DELEGATE_HEAD ): 288 bytes
Type 1D (OBJECT_TO_EVENT ): 216 bytes
Type 1E (BINARY_BLOB_HEAD ): 8172 bytes
Type 1F (THREAD ): 1536 bytes
Type 20 (SUBTHREAD ): 192 bytes
Type 21 (STACK_FRAME ): 972 bytes
Type 27 (FINALIZER_HEAD ): 264 bytes
Type 31 (IO_PORT ): 252 bytes
Type 34 (APPDOMAIN_HEAD ): 72 bytes
Type 36 (APPDOMAIN_ASSEMBLY ): 1356 bytes
GC: 2msec 43872 bytes used, 20508 bytes available
Type 0F (STRING ): 816 bytes
Type 11 (CLASS ): 3468 bytes
Type 12 (VALUETYPE ): 216 bytes
Type 13 (SZARRAY ): 10140 bytes
Type 15 (FREEBLOCK ): 20508 bytes
Type 17 (ASSEMBLY ): 12396 bytes
Type 18 (WEAKCLASS ): 48 bytes
Type 19 (REFLECTION ): 12 bytes
Type 1B (DELEGATE_HEAD ): 360 bytes
Type 1D (OBJECT_TO_EVENT ): 312 bytes
Type 1E (BINARY_BLOB_HEAD ): 9240 bytes
Type 1F (THREAD ): 1536 bytes
Type 20 (SUBTHREAD ): 192 bytes
Type 21 (STACK_FRAME ): 2928 bytes
Type 27 (FINALIZER_HEAD ): 384 bytes
Type 31 (IO_PORT ): 396 bytes
Type 34 (APPDOMAIN_HEAD ): 72 bytes
Type 36 (APPDOMAIN_ASSEMBLY ): 1356 bytes
GC: 2msec 39072 bytes used, 25308 bytes available
Type 0F (STRING ): 600 bytes
Type 11 (CLASS ): 3360 bytes
Type 12 (VALUETYPE ): 192 bytes
Type 13 (SZARRAY ): 9888 bytes
Type 15 (FREEBLOCK ): 25308 bytes
Type 17 (ASSEMBLY ): 12396 bytes
Type 18 (WEAKCLASS ): 48 bytes
Type 19 (REFLECTION ): 24 bytes
Type 1B (DELEGATE_HEAD ): 360 bytes
Type 1D (OBJECT_TO_EVENT ): 312 bytes
Type 1E (BINARY_BLOB_HEAD ): 6792 bytes
Type 1F (THREAD ): 1536 bytes
Type 20 (SUBTHREAD ): 192 bytes
Type 21 (STACK_FRAME ): 1188 bytes
Type 27 (FINALIZER_HEAD ): 360 bytes
Type 31 (IO_PORT ): 396 bytes
Type 34 (APPDOMAIN_HEAD ): 72 bytes
Type 36 (APPDOMAIN_ASSEMBLY ): 1356 bytes
GC: 2msec 40896 bytes used, 23484 bytes available
Type 0F (STRING ): 648 bytes
Type 11 (CLASS ): 3636 bytes
Type 12 (VALUETYPE ): 192 bytes
Type 13 (SZARRAY ): 9912 bytes
Type 15 (FREEBLOCK ): 23484 bytes
Type 17 (ASSEMBLY ): 12396 bytes
Type 18 (WEAKCLASS ): 48 bytes
Type 19 (REFLECTION ): 24 bytes
Type 1B (DELEGATE_HEAD ): 360 bytes
Type 1D (OBJECT_TO_EVENT ): 312 bytes
Type 1E (BINARY_BLOB_HEAD ): 7860 bytes
Type 1F (THREAD ): 1536 bytes
Type 20 (SUBTHREAD ): 192 bytes
Type 21 (STACK_FRAME ): 1572 bytes
Type 27 (FINALIZER_HEAD ): 384 bytes
Type 31 (IO_PORT ): 396 bytes
Type 34 (APPDOMAIN_HEAD ): 72 bytes
Type 36 (APPDOMAIN_ASSEMBLY ): 1356 bytes
GC: 2msec 44832 bytes used, 19548 bytes available
Type 0F (STRING ): 648 bytes
Type 11 (CLASS ): 3636 bytes
Type 12 (VALUETYPE ): 192 bytes
Type 13 (SZARRAY ): 14028 bytes
Type 15 (FREEBLOCK ): 19548 bytes
Type 17 (ASSEMBLY ): 12396 bytes
Type 18 (WEAKCLASS ): 48 bytes
Type 19 (REFLECTION ): 24 bytes
Type 1B (DELEGATE_HEAD ): 360 bytes
Type 1D (OBJECT_TO_EVENT ): 312 bytes
Type 1E (BINARY_BLOB_HEAD ): 7860 bytes
Type 1F (THREAD ): 1536 bytes
Type 20 (SUBTHREAD ): 192 bytes
Type 21 (STACK_FRAME ): 1392 bytes
Type 27 (FINALIZER_HEAD ): 384 bytes
Type 31 (IO_PORT ): 396 bytes
Type 34 (APPDOMAIN_HEAD ): 72 bytes
Type 36 (APPDOMAIN_ASSEMBLY ): 1356 bytes
Failed allocation for 685 blocks, 8220 bytes
GC: 2msec 49608 bytes used, 14772 bytes available
Type 0F (STRING ): 648 bytes
Type 11 (CLASS ): 3648 bytes
Type 12 (VALUETYPE ): 192 bytes
Type 13 (SZARRAY ): 22248 bytes
Type 15 (FREEBLOCK ): 14772 bytes
Type 17 (ASSEMBLY ): 12396 bytes
Type 18 (WEAKCLASS ): 48 bytes
Type 19 (REFLECTION ): 24 bytes
Type 1B (DELEGATE_HEAD ): 360 bytes
Type 1D (OBJECT_TO_EVENT ): 312 bytes
Type 1E (BINARY_BLOB_HEAD ): 4080 bytes
Type 1F (THREAD ): 1536 bytes
Type 20 (SUBTHREAD ): 192 bytes
Type 21 (STACK_FRAME ): 1716 bytes
Type 27 (FINALIZER_HEAD ): 384 bytes
Type 31 (IO_PORT ): 396 bytes
Type 34 (APPDOMAIN_HEAD ): 72 bytes
Type 36 (APPDOMAIN_ASSEMBLY ): 1356 bytes
Failed allocation for 685 blocks, 8220 bytes
GC: 2msec 49608 bytes used, 14772 bytes available
Type 0F (STRING ): 648 bytes
Type 11 (CLASS ): 3648 bytes
Type 12 (VALUETYPE ): 192 bytes
Type 13 (SZARRAY ): 22248 bytes
Type 15 (FREEBLOCK ): 14772 bytes
Type 17 (ASSEMBLY ): 12396 bytes
Type 18 (WEAKCLASS ): 48 bytes
Type 19 (REFLECTION ): 24 bytes
Type 1B (DELEGATE_HEAD ): 360 bytes
Type 1D (OBJECT_TO_EVENT ): 312 bytes
Type 1E (BINARY_BLOB_HEAD ): 4080 bytes
Type 1F (THREAD ): 1536 bytes
Type 20 (SUBTHREAD ): 192 bytes
Type 21 (STACK_FRAME ): 1716 bytes
Type 27 (FINALIZER_HEAD ): 384 bytes
Type 31 (IO_PORT ): 396 bytes
Type 34 (APPDOMAIN_HEAD ): 72 bytes
Type 36 (APPDOMAIN_ASSEMBLY ): 1356 bytes
Failed allocation for 685 blocks, 8220 bytes
#### Exception System.OutOfMemoryException - CLR_E_OUT_OF_MEMORY (1) ####
#### Message:
#### System.IO.StreamReader::ReadLine [IP: 000a] ####
#### NavSystem.Program::RecallStuff [IP: 0017] ####
#### NavSystem.Program::Main [IP: 0127] ####
A first chance exception of type ‘System.OutOfMemoryException’ occurred in System.IO.dll
GC: 2msec 43392 bytes used, 20988 bytes available
Type 0F (STRING ): 672 bytes
Type 11 (CLASS ): 3708 bytes
Type 12 (VALUETYPE ): 192 bytes
Type 13 (SZARRAY ): 14076 bytes
Type 15 (FREEBLOCK ): 20988 bytes
Type 17 (ASSEMBLY ): 12396 bytes
Type 18 (WEAKCLASS ): 48 bytes
Type 19 (REFLECTION ): 24 bytes
Type 1B (DELEGATE_HEAD ): 360 bytes
Type 1D (OBJECT_TO_EVENT ): 312 bytes
Type 1E (BINARY_BLOB_HEAD ): 6240 bytes
Type 1F (THREAD ): 1536 bytes
Type 20 (SUBTHREAD ): 192 bytes
Type 21 (STACK_FRAME ): 1428 bytes
Type 27 (FINALIZER_HEAD ): 384 bytes
Type 31 (IO_PORT ): 396 bytes
Type 34 (APPDOMAIN_HEAD ): 72 bytes
Type 36 (APPDOMAIN_ASSEMBLY ): 1356 bytes
An unhandled exception of type ‘System.OutOfMemoryException’ occurred in System.IO.dll
The code…
static void RecallStuff()
{
FileStream FileHandle;
StreamReader sr;
string s;
string[] Words;
// Assume one storage device is available
FileHandle = new FileStream(@ "\SD\Warnings\Config.cfg", FileMode.Open, FileAccess.Read);
// recall search range, proximity alarm, DST flag, lon and lat
sr = new StreamReader(FileHandle);
s = sr.ReadLine();
Words = s.Split(',');
SearchRange = int.Parse(Words[0]);
AlarmThreshold = int.Parse(Words[1]);
Dst = (int.Parse(Words[2])==1 ? true : false);
SampledLat = double.Parse(Words[3]);
SampledLon = double.Parse(Words[4]);
FileHandle.Close();
}
I know this code is not very robust and makes a lot of assumtions, but all being well it should work.
Any thoughts??