diff --git a/CHANGELOG.md b/CHANGELOG.md index 75dec68f..b81efc03 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -23,3 +23,4 @@ HEAD * `JsonDocument`'s allocator is not monotonic anymore, removed values get recycled * Show a link to the documentation when user passes an unsupported input type * Remove `JsonDocument::memoryUsage()` +* Remove `JsonDocument::garbageCollect()` diff --git a/extras/tests/JsonDocument/CMakeLists.txt b/extras/tests/JsonDocument/CMakeLists.txt index 112e9c25..1a58d745 100644 --- a/extras/tests/JsonDocument/CMakeLists.txt +++ b/extras/tests/JsonDocument/CMakeLists.txt @@ -11,7 +11,6 @@ add_executable(JsonDocumentTests containsKey.cpp createNested.cpp ElementProxy.cpp - garbageCollect.cpp isNull.cpp issue1120.cpp MemberProxy.cpp diff --git a/extras/tests/JsonDocument/garbageCollect.cpp b/extras/tests/JsonDocument/garbageCollect.cpp deleted file mode 100644 index 808d7298..00000000 --- a/extras/tests/JsonDocument/garbageCollect.cpp +++ /dev/null @@ -1,50 +0,0 @@ -// ArduinoJson - https://arduinojson.org -// Copyright © 2014-2023, Benoit BLANCHON -// MIT License - -#include -#include // malloc, free -#include -#include - -#include "Allocators.hpp" - -using ArduinoJson::detail::sizeofObject; -using ArduinoJson::detail::sizeofString; - -TEST_CASE("JsonDocument::garbageCollect()") { - ControllableAllocator controllableAllocator; - SpyingAllocator spyingAllocator(&controllableAllocator); - JsonDocument doc(&spyingAllocator); - - SECTION("when allocation succeeds") { - deserializeJson(doc, "{\"blanket\":1,\"dancing\":2}"); - doc.remove("blanket"); - spyingAllocator.clearLog(); - - bool result = doc.garbageCollect(); - - REQUIRE(result == true); - REQUIRE(doc.as() == "{\"dancing\":2}"); - REQUIRE(spyingAllocator.log() == - AllocatorLog() << AllocatorLog::Allocate(sizeofString(7)) - << AllocatorLog::Allocate(sizeofPool()) - << AllocatorLog::Deallocate(sizeofString(7)) - << AllocatorLog::Deallocate(sizeofPool())); - } - - SECTION("when allocation fails") { - deserializeJson(doc, "{\"blanket\":1,\"dancing\":2}"); - doc.remove("blanket"); - controllableAllocator.disable(); - spyingAllocator.clearLog(); - - bool result = doc.garbageCollect(); - - REQUIRE(result == false); - REQUIRE(doc.as() == "{\"dancing\":2}"); - - REQUIRE(spyingAllocator.log() == - AllocatorLog() << AllocatorLog::AllocateFail(sizeofString(7))); - } -} diff --git a/extras/tests/JsonDocument/overflowed.cpp b/extras/tests/JsonDocument/overflowed.cpp index fa716ea9..9267881e 100644 --- a/extras/tests/JsonDocument/overflowed.cpp +++ b/extras/tests/JsonDocument/overflowed.cpp @@ -80,11 +80,4 @@ TEST_CASE("JsonDocument::overflowed()") { doc.shrinkToFit(); CHECK(doc.overflowed() == true); } - - SECTION("return false after garbageCollect()") { - allocator.setCountdown(0); - doc.add(0); - doc.garbageCollect(); - CHECK(doc.overflowed() == false); - } } diff --git a/src/ArduinoJson/Document/JsonDocument.hpp b/src/ArduinoJson/Document/JsonDocument.hpp index 76bd1ff0..8c6048b8 100644 --- a/src/ArduinoJson/Document/JsonDocument.hpp +++ b/src/ArduinoJson/Document/JsonDocument.hpp @@ -76,17 +76,6 @@ class JsonDocument : public detail::VariantOperators { resources_.shrinkToFit(); } - // Reclaims the memory leaked when removing and replacing values. - // https://arduinojson.org/v6/api/jsondocument/garbagecollect/ - bool garbageCollect() { - // make a temporary clone and swap - JsonDocument tmp(*this); - if (tmp.overflowed()) - return false; - swap(*this, tmp); - return true; - } - // Casts the root to the specified type. // https://arduinojson.org/v6/api/jsondocument/as/ template