Here is an implementation: I am running delete keyword on two different struct variables. on storage variable remix gives an error but not on memory. Why is this so?

pragma solidity ^0.4.0;

contract myContract
    struct abc {
        uint8[] m;
        uint a ;

    function myFucn() returns(bool)
        abc storage b;   
        abc memory a;
        delete a;
        delete b; // error unary operator cannot be applied to storage pointer.
        return true;
  • Are you sure there is not mistake in your post? From my undertanding, it would be a that you would not be able to delete. Jan 12, 2018 at 3:27
  • Yes I wasn't but why? Jan 12, 2018 at 8:31
  • Because, from my understanding, I may be wrong, you can't delete memory variable because they don't have pointers (they are not actually stored), but storage variable have a pointer (obvisouly), like i C language. Jan 12, 2018 at 9:34

1 Answer 1

abc storage b;

is declaring an uninitialized storage pointer, it should be used to point to some variable in storage.

It is not possible to delete a storage pointer, even if it has been initialized, as stated in the solidity documentation. Deleting it would "reset" the pointer, but there is no sensible location for it to point to, so it is not allowed.

However, if you had a state variable (which is implicitly stored in storage), you could delete this directly e.g. the following is allowed

contract MyContract {
    string myStorageVariable;

    function removeTheVariable(string strArg) public {
        myStorageVariable = strArg;
        delete myStorageVariable;

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.