ESP32 NVS Erase Key Does Not Clear Data
DodaTech
Updated 2026-06-26
1 min read
In this tutorial, you'll learn about ESP32 NVS Erase Key Does Not Clear Data. We cover key concepts, practical examples, and best practices.
The Problem
ESP32 NVS erase_key() returns success but the key still exists when read.
Quick Fix
Wrong
nvs_erase_key(handle, "temp"); // Don't forget to commit
nvs_get_i32(handle, 'temp', &val) still returns old value.
Right
esp_err_t err = nvs_erase_key(handle, "temp");
if (err == ESP_OK) {
nvs_commit(handle); // Must commit erase
Serial.println("Key erased");
} else if (err == ESP_ERR_NVS_NOT_FOUND) {
Serial.println("Key did not exist");
} else {
Serial.printf("Erase failed: %s\n", esp_err_to_name(err));
}
// Verify
err = nvs_get_i32(handle, "temp", &val);
if (err == ESP_ERR_NVS_NOT_FOUND) {
Serial.println("Verified: key deleted");
}
Key erased
Verified: key deleted
Prevention
Call nvs_commit() after nvs_erase_key(). Check return code for ESP_ERR_NVS_NOT_FOUND. Verify deletion by attempting to read the key. Erase all keys in a namespace with nvs_erase_all(handle).
DodaTech engineers apply these same patterns across Doda Browser, DodaZIP, and Durga Antivirus Pro for production IoT reliability.
FAQ
Built by the developers of DodaTech
Doda Browser, DodaZIP & Durga Antivirus Pro