Memory Management

I’m new to Netduino but not embedded development. I’ve inherited a project based on Netduino I need to maintain and to which I need to add features.I’ve got the latest setup with VS2015, SDK v5, etc.

I’m running into a problem there Visual Studio is crashing after I’m getting error message in the debugging window that memory can’t be allocated. It is frustrating that a memory issue on the target is crashing the development environment but after a few hours of searching and reading it seems like I can’t find any documentation on the micro framework or any tools to help me understand how memory is managed on the Netduino.So my questions are:

  • How do I find out how much memory I have available to me and how much is free at any point in the application running? Are there any features in Visual Studio or any functions I can call to find out the state of the heap?

  • Are there any good documentation sources that can help me understand under which circumstances is a string taking up RAM vs. what can I do to make sure it is stored in FLASH?

  • Are there any other tools or API calls that would be useful to help me manage my RAM and FLASH utilization?

Thanks.

Expert .NET MicroFramework, by Jens Kühner, published by Apress has a section on memory management, etc. It’s probably the most advanced book on the subject. It’s not super robust, but ExtendedWeakReferences and WeakDelegates might just be the thing you need - that’s what will allow you to store your string in flash as opposed to RAM. Miloush.net also has an article on the subject here.

In terms of getting current allocated memory, I thought that GC.GetTotalMemory() was available in .NETMF. Have you tried that?

In terms of the crash, can you create a repro app and file a bug here?

Thanks for the response. GC.GetTotalMemory() is not available with Microframework on my setup as it currently is configured. But the Microsoft documentation says it should be available in .NET but it isn’t clear if it should be available in the microframework.

If you are sure it should be available what could I be missing in my development environment that prevents me from getting access to that function?

Hi

You wouldn’t happen to be doing serial coms? Some of the GPS libraries don’t handle buffer overruns etc. well

I found manually chopping up NMEA strings as bytes rather than more conventional string operations on Unicode text was more robust.

Simplest possible snippet to work out memory utilisation…

using System;
using System.Threading;
using Microsoft.SPOT;

public class Program
{
   public static void Main()
   {
      while (true)
      {
         Debug.Print("Memory: " + Microsoft.SPOT.Debug.GC(true).ToString());
         Thread.Sleep(30000);
      }
   }
}

The amount of debugging info you get out depends on the NetMF build which varies by vendor/device etc.

I used this approach to find https memory leak on GHI Fez spider. For more background see

@KiwiBryn