I know there are previous answers around this, but things have changed new EIP's:

Right now I'm using an array of structs, for something I only do in memory. It's very messy code and would be much simpler as mapping (with no arrays) — but I'm avoiding that due to the gas for storage writes. If I instead used a mapping, and deleted the mapping at the end of the function, would gas be comparable?

1 Answer 1


I don't think you can delete a mapping because Solidity does not know the keys for the mapping. However, individual keys and what they map to can be deleted: If a is a mapping, then delete a[x] will delete the value stored at x. Deleting a mapping entry does result in a gas refund, and deleting a variable generally refunds 15,000 gas up to a maximum of half the gas cost of the transaction.



Is there a need to remove entries from mapping?


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.