What happens when a controller is out of memory?

I curious about how an arduino controller behave when there is no more memory left.

Assume the following function:

function foobar()
{
  const int numbersOfElements = 10;

  uint32_t  elemnts[numberOfElements];
  ...
}

If the numberOfElements is set high enough there will be a memory problem. And what happen then? Does the controller freeze or do I get an unpredictable behavior?

When you run the stack into the heap like that, assuming you actually write on that array, you'll get unpredictable behavior. Your program may behave strangely or stop responding altogether.

What happens when a controller is out of memory?

This is the first time I have come across a situation where the simplistic "my program doesn't work" seems to be the correct answer.

...R

What happens is correctly stated by wildbill. As your code uses RAM it builds from the low end to the high end (address). There are no limit checks. Your stack (like an array with a pointer) starts writing in reverse order in the array. It has its high end starting point defined but it has no bounders so it keeps using memory, then assume something writes to that area assuming it is part of one of its array locations which it would be it overwrites something(s) on the stack. That could be returned values but it could also be the program counter. Then when the processor does a return from the call, interrupt, etc it gets a wrong address At this point there is no way of defining where it will go and it does not know the difference between instructions and data so it will probably start interpreting data as instructions.
Good Luck & Have Fun!
Gil

gilshultz:
At this point there is no way of defining where it will go and it does not know the difference between instructions and data so it will probably start interpreting data as instructions.

Because the return address will be in program memory, the address will almost certainly contain instructions.

TheMemberFormerlyKnownAsAWOL:
Because the return address will be in program memory, the address will almost certainly contain instructions.

True, but if there are any multi-byte instructions, you could in up in the middle of an instruction, with totally unpredictable results.

thehardwareman:
I curious about how an arduino controller behave when there is no more memory left.

Assume the following function:

function foobar()

{
 const int numbersOfElements = 10;

uint32_t  elemnts[numberOfElements];
 ...
}




If the numberOfElements is set high enough there will be a memory problem. And what happen then? Does the controller freeze or do I get an unpredictable behavior?

It will be like BSOD... without the blue screen or the text. The Arduino will either go into an endless reboot, crash, reboot loop or just stop working at all. Typically called "crash".