Netduino home hardware projects downloads community

Jump to content


The Netduino forums have been replaced by new forums at community.wildernesslabs.co. This site has been preserved for archival purposes only and the ability to make new accounts or posts has been turned off.
Photo

OutOfMemoryException [UPDATE]


  • Please log in to reply
6 replies to this topic

#1 Phil The Geek

Phil The Geek

    New Member

  • Members
  • Pip
  • 5 posts

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 phantomtypist

phantomtypist

    Advanced Member

  • Members
  • PipPipPip
  • 142 posts
  • LocationNew York, NY

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 Chris Walker

Chris Walker

    Secret Labs Staff

  • Moderators
  • 7767 posts
  • LocationNew York, NY

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 Mark H

Mark H

    Advanced Member

  • Members
  • PipPipPip
  • 70 posts
  • LocationPerth, Western Australia

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 Phil The Geek

Phil The Geek

    New Member

  • Members
  • Pip
  • 5 posts

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 Phil The Geek

Phil The Geek

    New Member

  • Members
  • Pip
  • 5 posts

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 Phil The Geek

Phil The Geek

    New Member

  • Members
  • Pip
  • 5 posts

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

home    hardware    projects    downloads    community    where to buy    contact Copyright © 2016 Wilderness Labs Inc.  |  Legal   |   CC BY-SA
This webpage is licensed under a Creative Commons Attribution-ShareAlike License.