user24069: I am a bit confused about how memory works in Arduino.  I have created an integer array like so:
int* arr = new int[3] {1, 2, 3};

When I go to delete it:
delete[] arr;

The first element is deleted, and all the remaining ones are still  present and accessible.
Serial.println(arr[0]); // prints 0
Serial.println(arr[1]); // prints 2
Serial.println(arr[2]); // prints 3


user18478: First of all: it is not a good idea to do dynamic memory maagement in embedded systems (in casu arduino)
Secondly freeing memory means: marking the memory as available. It does not mean "setting the memory to 0"
because ar still points to the same locaton in memory it is "normal" that it also still reads the old values. Only -according to the C CP0P0 pàrogramming rules- you should not do so. Reading will not cause problems but writing will very likely.

24069: <p>I am a bit confused about how memory works in Arduino.  I have created an integer array like so:</p>

<pre class="lang-cpp prettyprint-override"><code>int* arr = new int[3] {1, 2, 3};
</code></pre>

<p>When I go to delete it:</p>

<pre class="lang-cpp prettyprint-override"><code>delete[] arr;
</code></pre>

<p>The first element is deleted, and all the remaining ones are still  present and accessible.</p>

<pre class="lang-cpp prettyprint-override"><code>Serial.println(arr[0]); // prints 0
Serial.println(arr[1]); // prints 2
Serial.println(arr[2]); // prints 3
</code></pre>
 18478: <p>First of all: it is not a good idea to do dynamic memory maagement in embedded systems (in casu arduino)<br>
Secondly freeing memory means: marking the memory as available. It does not mean "setting the memory to 0"<br>
because <code>ar</code> still points to the same locaton in memory it is "normal" that it also still reads the old values. Only -according to the C CP0P0 pàrogramming rules- you should not do so. Reading will not cause problems but writing will very likely.</p>
