Excerpt from chapter 9 of the yellow paper, "Execution Model", describing the behaviour of the EMV when clearing storage:
This refund is effectively paid up-front since the initial usage of a storage location costs substantially more than normal usage.
This seems to counteract this StackExchange answer:
The gas refund is provided only 1 time, at the very end of the transaction's execution.
I also know that the refunded gas is capped at half of the execution costs, so this is confusing. Does the first statement mean that the refund is actually calculated up-front (formally, in the σ checkpoint state transition) but only transferred to the caller after the execution is finished?