# Solidity delete keyword **Published by:** [Primrose](https://paragraph.com/@primrose/) **Published on:** 2023-06-04 **URL:** https://paragraph.com/@primrose/solidity-delete-keyword ## Content Solidity의 deletesolidity에는 delete() 키워드가 있다. 다음과 같이 사용할 수 있다.// SPDX-License-Identifier: MIT pragma solidity ^0.8.9; contract MyContract { uint public number; uint[] public dynamicArr; uint[5] public fixedArr; mapping(uint => uint) public map; constructor() { number = 5; dynamicArr.push(5); fixedArr[0] = 5; map[0] = 5; } function deleteAll() external { delete number; // reset value to zero delete dynamicArr; // reduces size to 0 delete fixedArr; // reset all values to zero // delete map; // error delete map[0]; // ok } } uint, uint[], uint[5], mapping 자료구조에 사용한 것을 볼 수 있다. 어떤 자료형에 사용하느냐에 따라서 당연히 적용되는 방식이 다르다. 그러나 핵심은 하나이다.delete 키워드는 삭제가 아닌 재설정이다. 변수 값을 초기 기본 상태로 재설정할 수 있는 키워드이다.당연히 초기 기본 상태는 0이다. 마치 free() 함수를 이용해 메모리를 해제하는 것처럼 NULL(0)으로 만드는 것이다.정수(signed/unsigned)의 경우 변수를 0으로 설정한다.bool 변수의 경우 변수를 false로 설정한다.address 변수의 경우 변수를 0(기본값) 주소로 설정한다.고정 크기 배열 및 바이트의 경우 배열의 각 요소를 기본값으로 설정한다.동적 배열의 경우 모든 요소를 ​​제거하고 길이를 0으로 설정한다.구조체의 경우 각 멤버를 기본값으로 설정한다. ## Publication Information - [Primrose](https://paragraph.com/@primrose/): Publication homepage - [All Posts](https://paragraph.com/@primrose/): More posts from this publication - [RSS Feed](https://api.paragraph.com/blogs/rss/@primrose): Subscribe to updates