In Solidity smart contracts, there are 4 memory locations:
They all have different lifetimes and it’s not always easy to choose which one is right. In the below graph I drew their lifetimes against the execution of blocks, smart contract and functions.
Storage is the only memory location than span across block, i.e it persists to the blockchain.
Memory spans across multiple function executions in the same smart contract.
Stack last only as long as the function it is contained in.
And calldata is only available in the argument of the outer function executionSolidity