freeRam() causes freeze

If I knew how to modify source code, or write libraries, I would fix that. The way it is now it ridiculously inefficient. if you reserved blocks of 20 at a time, it wouldn't be that bad. but by adding 1 at a time... Jesus!

Thats like saying char[9] turns to char[10], of course you can't put char[10] in the heap that char[9] was in, it won't fit. so you do that so many times, and before you know it the heap is... donzo.

To be honest, i don't even know how to use a buffer, but the heap problem caused by Strings seems to be pretty obvious.

=========Edit=========
Why do they use Strings in the examples they provided in the wifi tutorials? That is not something you need to show a beginner that expects the examples to be something that can be built on.

Thomas499:
using the example WiFi Web Server...
...
However, if you connect to the internet page (if you only connect once) then it will freeze in 7 minutes after the connection due to some kind of cross code contamination witchery.

Sorry to break this to you but you are playing with inherently broken hardware.

This thread has the most complete summary of the many issues affecting the WiFi shields TCP communication.
http://forum.arduino.cc/index.php?topic=128424.0

I also did some experimenting myself.
http://mssystems.emscom.net/helpdesk/knowledgebase.php?article=51

Sorry to break this to you but you are playing with inherently broken hardware.

Thanks for letting me know it wasn't my code. I spent 3 days trying to debug to see why it was freezing. I'm kind of upset that i bought two $75 arduino wifi shields that don't work properly.

Does the Yun Shield have this issue as well?

Yun Shield is designed to solve the Internet connectivity and storage issue for Arduino Board.

I don't know if that means they fixed this problem, or if it means you can use wifi, Ethernet, whatever etc. to connect to the internet.

I switched my project to a Yun shortly after the Yun was launched. Essentially, the Yun is a Linux SoC connected to an Arduino Leonardo over a serial bridge. The IP stack is solid, the board has an embedded lighttpd web server and many other Linux packages can be installed. My Yun project is using NGinx to serve PHP pages, populated from a SQLite database. The downside is the serial bridge, which connects the Arduino sketch to the Linux SoC, is very slow. You can find much more info on the sub forum dedicated to the Yun.

Sorry, I have no experience with the Yun shield, yet.

Another option is an ESP8266, which I will be messing with over the winter.

I would imagine there is a queue of Arduino customers dissatisfied with the official WiFi shield. The WiFi shield is abandonware now, as it is superseded by the 101.

I use Strings a lot, and don't seem to have issues. I always declare the Strings in the code header instead of in the body of the code, and set the string to "" when its use is finished. While testing the below code has refreshed the web page over 500k times without hanging. The captured GET request strings are very short somewhat like the OP's. Like others have said, the official arduino wifi shield has issues that may be in play.

// zoomkat's meta refresh data frame test page 5/25/13
// use http://192.168.1.102:84 in your brouser for main page
// http://192.168.1.102:84/data static data page
// http://192.168.1.102:84/datastart meta refresh data page
// for use with W5100 based ethernet shields
// set the refresh rate to 0 for fastest update
// use STOP for single data updates

#include <SPI.h>
#include <Ethernet.h>

const int analogInPin0 = A0;
const int analogInPin1 = A1;
const int analogInPin2 = A2;
const int analogInPin3 = A3;
const int analogInPin4 = A4;
const int analogInPin5 = A5;

byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; //physical mac address
byte ip[] = { 192, 168, 1, 102 }; // arduino ip in lan
byte gateway[] = { 192, 168, 1, 1 }; // internet access via router
byte subnet[] = { 255, 255, 255, 0 }; //subnet mask
EthernetServer server(84); //server port
unsigned long int x=0; //set refresh counter to 0
String readString; 

//////////////////////

void setup(){
  Serial.begin(9600);
    // disable SD SPI if memory card in the uSD slot
  pinMode(4,OUTPUT);
  digitalWrite(4,HIGH);

  Ethernet.begin(mac, ip, gateway, gateway, subnet);
  server.begin();
  Serial.println("meta refresh data frame test 5/25/13"); // so I can keep track of what is loaded
}

void loop(){
  EthernetClient client = server.available();
  if (client) {
    while (client.connected()) {
      if (client.available()) {
        char c = client.read();
         if (readString.length() < 100) {
          readString += c; 
         } 
        //check if HTTP request has ended
        if (c == '\n') {

          //check get atring received
          Serial.println(readString);

          //output HTML data header
          client.println("HTTP/1.1 200 OK");
          client.println("Content-Type: text/html");
          client.println();

          //generate data page
          if(readString.indexOf("data") >0) {  //checks for "data" page
            x=x+1; //page upload counter
            client.print("<HTML><HEAD>");
            //meta-refresh page every 1 seconds if "datastart" page
            if(readString.indexOf("datastart") >0) client.print("<meta http-equiv='refresh' content='1'>"); 
            //meta-refresh 0 for fast data
            if(readString.indexOf("datafast") >0) client.print("<meta http-equiv='refresh' content='0'>"); 
            client.print("<title>Zoomkat's meta-refresh test</title></head><BODY>
");
            client.print("page refresh number: ");
            client.print(x); //current refresh count
            client.print("

");
            
              //output the value of each analog input pin
            client.print("analog input0 is: ");
            client.print(analogRead(analogInPin0));
            
            client.print("
analog input1 is: ");
            client.print(analogRead(analogInPin1));
                        
            client.print("
analog input2 is: ");
            client.print(analogRead(analogInPin2));
            
            client.print("
analog input3 is: ");
            client.print(analogRead(analogInPin3));
                                    
            client.print("
analog input4 is: ");
            client.print(analogRead(analogInPin4));
            
            client.print("
analog input5 is: ");
            client.print(analogRead(analogInPin5));
            client.println("
</BODY></HTML>");
           }
          //generate main page with iframe
          else
          {
            client.print("<HTML><HEAD><TITLE>Zoomkat's frame refresh test</TITLE></HEAD>");
            client.print("Zoomkat's Arduino frame meta refresh test 5/25/13");
            client.print("

Arduino analog input data frame:
");
            client.print("&nbsp;&nbsp;<a href='http://192.168.1.102:84/datastart' target='DataBox' title=''yy''>META-REFRESH</a>");
            client.print("&nbsp;&nbsp;&nbsp;&nbsp;<a href='http://192.168.1.102:84/data' target='DataBox' title=''xx''>SINGLE-STOP</a>");
            client.print("&nbsp;&nbsp;&nbsp;&nbsp;<a href='http://192.168.1.102:84/datafast' target='DataBox' title=''zz''>FAST-DATA</a>
");
            client.print("<iframe src='http://192.168.1.102:84/data' width='350' height='250' name='DataBox'>");
            client.print("</iframe>
</HTML>");
          }
          delay(1);
          //stopping client
          client.stop();
          //clearing string for next read
          readString="";
        }
      }
    }
  }
}

Like others have said, the official arduino wifi shield has issues that may be in play.

That was the problem. even the simple server wifi example without modification froze the arduino less than 10 minutes after calling the page once.

Zoomkat, do you have a yun shield or a ESP8266? If you do, what do you think of the speed? Do you have to use linux to use the WiFi or can you bypass it and use it without going through the slow linux part?

Here is an example that uses chars like Strings so there is no chance of heap fragmentation causing a crash to happen if you can use this on your examples ZoomKat

Global

static byte TempNC = 0;
const int MaxLenghtOfChar=80;
char currentLine[MaxLenghtOfChar];

part to substitute currentLine+=c; without using a String

    Serial.println("new client");           // print a message out the serial port
    //String currentLine = "";                // make a String to hold incoming data from the client
    TempNC=0;
    while (client.connected()) {            // loop while the client's connected
      if (client.available()) {             // if there's bytes to read from the client,
        char c = client.read();             // read a byte, then
       // Serial.write(c);                    // print it out the serial monitor
        if (c == '\n') {                    // if the byte is a newline character

          // if the current line is blank, you got two newline characters in a row.
          // that's the end of the client HTTP request, so send a response:
          if (TempNC == 0) {
            // HTTP headers always start with a response code (e.g. HTTP/1.1 200 OK)
            // and a content-type so the client knows what's coming, then a blank line:
            client.println("HTTP/1.1 200 OK");
            client.println("Content-type:text/html");
            client.println("Connection: close");  // the connection will be closed after completion of the responseSerial
            client.println();

            // the content of the HTTP response follows the header:
            client.print("Click <a href=\"/H\">here</a> turn the LED on pin 9 on
");
            client.print("Click <a href=\"/L\">here</a> turn the LED on pin 9 off
");

            // The HTTP response ends with another blank line:
            client.println();
            // break out of the while loop:
            break;
          }
          else {      // if you got a newline, then clear currentLine:
            //currentLine = "";
            TempNC=0;
            while (TempNC<MaxLenghtOfChar)
            { currentLine[TempNC]='\n';
              TempNC++;
            }
            TempNC=0;
            
          }
        }
        else if (c != '\r')                // you've gotten a character on the current line
        { if (TempNC<MaxLenghtOfChar)
          { 
            currentLine[TempNC]=c;
        if (PaulSsaysEndswithNotUsingStrings("GET /H"))
        Serial.println(F("LED ON"));
        else if (PaulSsaysEndswithNotUsingStrings("GET /L"))
        Serial.println(F("LED OFF"));
      TempNC++;
  }
        }
      }
    }
    // close the connection:
    client.stop();
    Serial.println("client disonnected");
  }

part that takes place of if( .endsWith("")) without using a String. I love reading about PaulS's hatred of Strings so I figured his name was worthy of the call function.

boolean PaulSsaysEndswithNotUsingStrings(char holder[])
{
  int i = TempNC-strlen(holder);
  if (i>=0)
  {
    static byte TempNT = 0;
    TempNT=0;
    boolean ok =1;
    while (i<TempNC && ok!=0)
    {
      if (holder[TempNT]!=currentLine[i])
          ok=0;
          TempNT++;
          i++;
        }
        if (ok==1)
        return 1;
        else
        return 0;
      } else return 0;
}

I never got an arduino wifi shield because of issues. I have a basic ESP8266 that I got some time back, but at the time there was a lot of fiddling with it so it wound up in the project box. I'm following the forum post where people actually have the chips so I may check it out soon.

Cross-posted about RAM issues alongside the WiFi shield here: modify freeRam() to find fragmentation - Programming Questions - Arduino Forum

To address Nick Gammons speculation. This thread was solved when I was informed the Wifi shield firmware was the cause of the crash rather than the amount of freeRam.

The cross post he speaks of is specific to finding a method to identify the amount of fragmentation using pointers, rather than anything that has to do with the WiFi shield, or crashes. In the "so called" cross post I simply want to find a way to calculate fragmentation.