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

Memory issues on Netduino Plus


  • Please log in to reply
2 replies to this topic

#1 vs3

vs3

    New Member

  • Members
  • Pip
  • 2 posts

Posted 09 August 2012 - 08:34 AM

I kept getting System.OutOfMemoryException for no apparent reason, so I tried the most simple test that I could think of:

        public static void Main()
        {
            String tmp = "";
            while (true)
            {
                Debug.Print("freemem : " + Debug.GC(true));
                tmp = tmp + "0123456789";
            }
        }

Debugger output:

freemem : 25284
freemem : 25272
freemem : 25260
freemem : 25248
freemem : 25248
freemem : 25236
freemem : 25224
    #### Exception System.OutOfMemoryException - CLR_E_OUT_OF_MEMORY (1) ####
    #### Message: 
    #### System.String::Concat [IP: 0000] ####
    #### NetduinoPlusApplication2.Program::Main [IP: 0020] ####
A first chance exception of type 'System.OutOfMemoryException' occurred in mscorlib.dll
An unhandled exception of type 'System.OutOfMemoryException' occurred in mscorlib.dll


I suspect the firmware on mine is way out of date:
HalSystemInfo.halVersion:               4.1.2821.0
HalSystemInfo.halVendorInfo:            Netduino Plus by Secret Labs LLC
HalSystemInfo.oemCode:                  34
HalSystemInfo.modelCode:                177
HalSystemInfo.skuCode:                  4097
HalSystemInfo.moduleSerialNumber:       00000000000000000000000000000000
HalSystemInfo.systemSerialNumber:       0000000000000000
ClrInfo.clrVersion:                     4.1.2821.0
ClrInfo.clrVendorInfo:                  Netduino Plus by Secret Labs LLC
ClrInfo.targetFrameworkVersion:         4.1.2821.0
SolutionReleaseInfo.solutionVersion:    4.1.0.6
SolutionReleaseInfo.solutionVendorInfo: Netduino Plus by Secret Labs LLC
SoftwareVersion.BuildDate:              Feb 14 2011
SoftwareVersion.CompilerVersion:        400902

so I guess I have a few questions:

#1 - The error makes absolutely no sense - with 25kb free... Is this the same issue that I see in this thread ?

#2 - if a newer firmware would fix my issues - how do I download that? (I looked at the downloads section on the web site but didn't see anything there)

#3 - any suggestions or ideas on how to fix that? Workarounds? Anything?

What I saw in my other application is quite close - similar crash when the memory gets down to about 25-26kb. That leaves us with about 5-6kb of actual usable RAM ... does that sound right?

Is there any reserved amount of RAM that we should have in mind? (25kb out of 32k total sounds like quite a lot to be honest)

#2 Chris Walker

Chris Walker

    Secret Labs Staff

  • Moderators
  • 7767 posts
  • LocationNew York, NY

Posted 09 August 2012 - 08:56 AM

Hi vs3, Behind the scenes, when you add to a string the NETMF creates a new object the size of the new string before garbage collecting the original string. The code is effectively allocating new, larger objects during each iteration. There are some pinned objects in memory which need to stay in the same place to handle native code callbacks, etc. It's quite possible that some of these are pinned in a location which keeps NETMF from allocation enough _contiguous_ bytes to your new strings. The free space needed may actually be in the area of your current string, ironically making it unavailable until the new string is created. If you create other values or objects, you'll be able to use much more of your memory. Also, .NET Micro Framework 4.2 has some enhancements in the garbage collector. If you want to update to the newest 4.2 beta release (RC5+), you may get more free memory for large arrays like your current one. Beta firmware is pinned at the top of the Beta Firmware forum. Finally...if you're building strings like this, I would recommend using StringBuilder (new in .NET Micro Framework 4.2). It is teh designated tool in .NET for the most efficient use of memory and/or fastest speed. Does that help? Chris

#3 vs3

vs3

    New Member

  • Members
  • Pip
  • 2 posts

Posted 11 August 2012 - 11:28 PM

Chris, first thanks for the quick reply! Yes, what you wrote does make sense and explains the issue to a great degree. I suspect the same issue would happen at any time when you have X = X + Y as it would first make the X' object and then dispose the X. That way I can see how another 5-7kb could be needed temporarily (which is how big X is at that time). It appears though that it uses 2 or even 3 times that amount of memory .. which I hope would be fixed in the 4.2 version.




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.