Hello Raj,
According to this document, the instance might be restarted when you add/remove/modify a flag. You may check the flags that require a restart by calling the list method of the API (just click execute without any modifications on this API page), and check the desired flag if “requiresRestart=True". For further information please check this document.
On the other hand, per "the tips with flags" page, “Exhausting the available instance memory can occur when you set tmp_table_size and max_heap_table_size too high for the number of concurrent queries the instance processes. Exhausting the memory will result in an instance crash and restart.” I hope this helps.