Netduino home hardware projects downloads community

Jump to content

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

OutOfMemory not expected

  • Please log in to reply
5 replies to this topic

#1 Nicolas Dorier

Nicolas Dorier


  • Members
  • PipPip
  • 24 posts

Posted 04 March 2011 - 08:37 AM

Hi, here is a really simple program :

ArrayList list = new ArrayList();
			for(int i = 0; i < 1000; i++)
				Log(i.ToString() + " " + Debug.GC(true).ToString());

And it seems that an OutOfMemoryException is raised very early... After 473 elements... and 14844 Bytes unused in the RAM

469 14940
470 14916
471 14892
472 14868
473 14844
#### Exception System.OutOfMemoryException - CLR_E_OUT_OF_MEMORY (1) ####

What is going on ?

#2 Chris Walker

Chris Walker

    Secret Labs Staff

  • Moderators
  • 7767 posts
  • LocationNew York, NY

Posted 04 March 2011 - 10:29 AM

Hi Nicolas, I haven't looked at how ArrayList is built internally, but is it possible that it's creating a new ArrayList pointer set every time you add an element to the list? [In other words, it would need to have 1x the size of the list available at all times.] I'm assuming that it's not implemented that way...but it might be. Do you get the error consistently after the same number of iterations? Could you please post a sample of your actual test project...and we can test it out here as well? Thanks! Chris

#3 Nicolas Dorier

Nicolas Dorier


  • Members
  • PipPip
  • 24 posts

Posted 04 March 2011 - 09:18 PM

Yes the error comes consistently. I have also tried to create several big byte array and it does not work even if it seems I have enough space. I can create 20 byte array of 512 element, but cannont create 1 byte array of 10 000. My guess is that internally, for the ArrayList and Array, the .NET try to get continuous memory blocks. Depending on the internal implementation of ArrayList, maybe after 473 elements, it tries to expand to a bigger array at twice as big as the source array of 473 elements. (and it seems that each elements takes 24 bytes) I send you all there different use case and the results I get with my netduino tomorrow.

#4 Nicolas Dorier

Nicolas Dorier


  • Members
  • PipPip
  • 24 posts

Posted 05 March 2011 - 03:02 PM

Here is the solution, my netduino is v

Attached Files

#5 Corey Kosak

Corey Kosak

    Advanced Member

  • Members
  • PipPipPip
  • 276 posts
  • LocationHoboken, NJ

Posted 07 March 2011 - 01:55 AM

and it seems that each elements takes 24 bytes

I feel your pain. We discussed this issue in depth on the first page of this topic.

Regarding your failure to create a 10000 element array, I've also seen that happen. I don't have a solid explanation yet in that case but I've been meaning to figure it out one of these days.

#6 Earthed



  • Members
  • PipPip
  • 20 posts
  • LocationAustralia

Posted 30 August 2011 - 12:44 PM

I have had an interesting issue arrise and not cause an exception immediately upon calling: char[] chars = new char[mBufferMax]; //where mBufferMax=500, chars[128] was created, not chars[500]! very shortly after I got a CLR_E_OUT_OF_MEMORY (1) PS: Whats the difference between the following? CLR_E_OUT_OF_MEMORY (1) CLR_E_OUT_OF_MEMORY (3)

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.