The blockchain is an immutable, append-only transaction set. I have the following questions regarding delete keyword -

Then what is the purpose of deletekeyword in solidity?

Is it only for variables stored in memory?

Is it possible to delete variables stored in storage and stack?

What are all the possible cases in which delete keyword should be used and where it should not be?

2 Answers 2


delete is actually not really deletion at all - it's only assigning a default value back to variables. It does not make difference whether the variable is in memory or in storage.

For example, issuing a delete to a uint variable simply sets the variable's value to 0.

delete will also give a bit of your used gas back - this is to encourage deleting variables after their data is no longer needed so the size of the blockchain would stay a bit smaller. Note that you can never regain more gas than what your current transaction is using.

You can read more about delete here: https://docs.soliditylang.org/en/v0.8.17/types.html?highlight=delete#delete


See the answer of stackexchange Short description about delete

And also follow the link of soldityreadthedocs.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.