The lamp will turn itself off after the test runs and passes three
consecutive times. Depending on the test, this could be every time the
vehicle is started, or some other more complicated and convoluted
interval. In the industry, we use the term "drive cycle," which at least
involves a cold start and reaching operating temperature.
The code itself will remain longer. I haven't needed this information in
practical usage, and it's been so long since I've learned it, I've
forgotten how long the code itself will remain.