Arduino UNO freezes with simple sketch after ~1 minute

This is the sketch. Around a minute from code upload it freezes. I have leds connected to pins 2 to 8. After a minute or so all leds stop blinking, the all stay ON until I reset it
[update]: happens with Mega 2560 too

unsigned int timer=0;
bool sw=0;
void setup()
{
  for(int i=2;i<=8;i++)
  {
    pinMode(i,OUTPUT);
  }
}

void loop()
{
  if(millis()-timer > 250)
  {
    if(sw==0){
      sw=1;
    }
    else{
      sw=0;
    }
    timer = millis();
  }
  for(int i=2;i<=8;i++)
  {
    if(sw)
    {
      digitalWrite(i,HIGH);
      digitalWrite(i,LOW);
    }
    else{
      digitalWrite(i,LOW);
    }
  }
}

Any ideas?

change this unsigned int timer=0; to unsigned long timer = 0;

same data type as millis( ).

So… it overflows, hah, Thanks

Yep.