petroleum refining- what are those stacks with the flames at the top

In the downriver Detroit metro area, there are several oil refineries which I drive past fairly regularly. There’s always at least several fairly tall and skinny chimneys/stacks which have flames burning at the top. What are they burning off? If it’s a combustible/flammable gas, wouldn’t it be something better captured and used rather than just making a giant metal candle?

On oil production rigs, in refineries and chemical plants, its primary purpose is to act as a safety device to protect vessels or pipes from over-pressuring due to unplanned upsets.
Flare gas recovery systems are occasionally used to collect low flows of waste gas and return it to the Process Plant as opposed to burning the gas

Thanks. Bonus: I love learning new technical jargon.

Here’s the sort of thing that safety device is intended to prevent:

Texas City Refinery Explosion

Specifically:

Note that BP itself was aware of the need to install a flare system:

15 people were killed and 170 injured in the explosion and subsequent fire.