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

How to work on out of memory errors?


  • Please log in to reply
24 replies to this topic

#21 Miha

Miha

    Advanced Member

  • Members
  • PipPipPip
  • 94 posts

Posted 04 November 2012 - 01:17 PM

I noticied out of memory issue again. It seems that it is affected by the work on other threads as well (which makes sense), but still, .NET MF reports that it has 20+ kB left, so it is puzzling. Additional question: will I have more memory if I deploy the release version of the program on the device (instead of debug build)? Regards, Miha.

#22 Chris Walker

Chris Walker

    Secret Labs Staff

  • Moderators
  • 7767 posts
  • LocationNew York, NY

Posted 04 November 2012 - 04:19 PM

Hi Miha,

I noticied out of memory issue again. It seems that it is affected by the work on other threads as well (which makes sense), but still, .NET MF reports that it has 20+ kB left, so it is puzzling.

Some objects in memory are pinned in place. So you may have 20KB+ of memory left--but it may be in chunks which are smaller than the total amount of contiguous space your application is asking for. There may also be some larger temporary pieces of memory needed to complete an operation, such as string concatenation, and those will need contiguous chunks as well.

Additional question: will I have more memory if I deploy the release version of the program on the device (instead of debug build)?


The Visual Studio debugger takes several KB of memory. To demonstrate that, put the following line of code first in your application:
Debug.Print("freemem: " + Debug.GC(true));
Run your app from Visual Studio. Now stop your app, connect via MFDeploy, reboot your board, and Ping from MFDeploy. You'll now see a larger number :)

Chris

#23 Miha

Miha

    Advanced Member

  • Members
  • PipPipPip
  • 94 posts

Posted 04 November 2012 - 06:14 PM

Some objects in memory are pinned in place. So you may have 20KB+ of memory left--but it may be in chunks which are smaller than the total amount of contiguous space your application is asking for. There may also be some larger temporary pieces of memory needed to complete an operation, such as string concatenation, and those will need contiguous chunks as well.


Yes, I understand that. It's just hard to debug, since OutOfMem errors are sporadic :)


The Visual Studio debugger takes several KB of memory. To demonstrate that, put the following line of code first in your application:

Debug.Print("freemem: " + Debug.GC(true));
Run your app from Visual Studio. Now stop your app, connect via MFDeploy, reboot your board, and Ping from MFDeploy. You'll now see a larger number :)


Thanks for the tip. So, this means that there is no difference between debug/release builds? Only if I deploy/debug it via VS vs. MFDeploy?

Regards,
Miha.

#24 H07R0D

H07R0D

    Advanced Member

  • Members
  • PipPipPip
  • 95 posts

Posted 07 November 2012 - 07:10 PM

One thing that's saved me a lot of space has been to avoid any of the 'bigger' stream objects, and sticking with just FileStreams.

Opening a FileStream has the added benefit of not having to check for File.Exists thanks to the FileMode Enumeration. It takes care of appends/overwrites for you.
The only thing you'll have to watch is you're dealing with bytes, not strings, but that's really easy to handle too, with Encoding.UTF8.GetBytes().

For my Aquarium Controller, I was hitting memory problems all the time since it's running a web server, a task scheduler, and various plugins for sensor input/output.
Ditching Text and Stream writers saved lots of valuable space.

#25 Miha

Miha

    Advanced Member

  • Members
  • PipPipPip
  • 94 posts

Posted 07 November 2012 - 07:13 PM

Thanks, I'll try that. I'm only writing a couple of settings to file, so doing it with FileStream is not going to be a problem.




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.