Variables reset when opening/closing serial monitor

So I'm trying to run the script below as a test for reading from the serial. I open the serial monitor, write letters to it, type 'x' to see that it stored the letters. I now close the serial monitor, reopen it, then the L LED on my Arduino UNO flashes 4 times quickly, and then when I type "x" in the serial monitor, it's clear that the String variable values has reset. Is this normal? Am I running out of memory exactly when I reopen the serial monitor?

int val; // Value read from the serial port
String values = "";

void setup()

void loop()
    // Read from serial port
    if (Serial.available())
        val =;
        values = values + (char) val;
        if (val == 'x')

When you reopen the serial monitor on the Uno R3, it causes a reset signal, and the processor starts over.