arduino lost sync with ROS

I know a lot of people have this issue. How do you resolve this issue? Is it because Arduino does not have enough RAM

I am using Arduino Mega 2560

What is ROS ?
If a hardware serial port is used, it can't go wrong as long as the voltage levels match and the signal is a clean digital signal and the buffer in the Serial library is not full.
I don't know anymore what the size of the input buffer is, perhaps 32 byte. When more than 32 bytes are received at a very high baudrate, and the sketch does not retrieve them from the buffer, then bytes could be missed.

ROS == Robot Operating System

Many 8-bit Arduinos based on the Atmega328P flavor only have 2K of SRAM. The Leonardo has 2.5K but some is consumed by USB.
The Mega2560 has 8K SRAM.
The boards based on 1284P have 16K SRAM (Bobduino, etc.) 1284P

If you need more than 16K, then consider the Teensy3.1, the Arduino Due, or a clone 32-bit board.