OutOfMemoryException [UPDATE]
Started by Phil The Geek, Jan 27 2011 07:35 PM
6 replies to this topic
#1
Posted 27 January 2011 - 07:35 PM
I'm getting an OutOfMemoryException when I try to open a StreamWriter to an SD card. Have I missed something or am I genuinely out of memory? If I am out of memory is there any form of profiling available to see what's hogging the memory?
Cheers
Phil
#2
Posted 27 January 2011 - 08:57 PM
I'm getting an OutOfMemoryException when I try to open a StreamWriter to an SD card. Have I missed something or am I genuinely out of memory? If I am out of memory is there any form of profiling available to see what's hogging the memory?
Cheers
Phil
Can you post a sample of your application and also tell us what firmware version you are using?
#3
Posted 27 January 2011 - 09:45 PM
Hi Phil,
If you use Debug.GC(true) it will tell you how much memory is free...you can use this to as a diagnostic.
Chris
#4
Posted 28 January 2011 - 04:54 AM
Your stream buffers may be using too much memory - i've had this problem with not clearing the buffer from a serial port fast enough. Try calling .Flush() on your stream occasionally to force the data out - especially if you have just sent a large amount of data to it.
#5
Posted 28 January 2011 - 07:39 AM
I was running Firmware 4.1.0.5, I've updated to 4.1.1.0a5, both with the same result.
Code Snippet:
bool ProcessZoneFile()
{
StreamWriter swZone;
// other code for testing existence of directories and files
// this is returning 16392
uint nFree=Debug.GC(true);
// then this line is failing
swZone = new StreamWriter(strSD+"\\config\\zones.dat");
//more code that I'm never getting to
}
#6
Posted 28 January 2011 - 08:07 AM
As this was one of the initialisation routines, I've moved it earlier in the initialisation sequence and the problem's gone away. When the StreamWriter is being called now there are about 20500 bytes free. It's now called before any other streams are created.
Cheers for the help.
Phil
#7
Posted 01 February 2011 - 07:46 PM
Turns out that I was a bit premature in stating I'd fixed the issue. I now strongly believe that the issue lies with the MF's implementation of StreamWriter whereby it doesn't provide the buffer size option that the full version does. As a result it tries to utilise a buffer of 4095 bytes which for some reason is causing memory exceptions.
It would be useful if the additional constructor could be requested for the framework as this would remove the need for workarounds.
My workaround was to use a FileStream instead which is a bit more coding and less friendly but it works.
Cheers
Phil
0 user(s) are reading this topic
0 members, 0 guests, 0 anonymous users