diff --git a/sources/Data/JSON/JArray.uc b/sources/Data/JSON/JArray.uc index 70d8476..97ed632 100644 --- a/sources/Data/JSON/JArray.uc +++ b/sources/Data/JSON/JArray.uc @@ -481,15 +481,27 @@ public final function JArray AddObject() // Returns `true` if value was actually removed and `false` if it didn't exist. public final function bool RemoveValue(int index, optional int amount) { + local int i; if (index < 0) return false; if (index >= data.length) return false; amount = Max(amount, 1); amount = Min(amount, data.length - index); + for (i = index; i < index + amount; i += 1) + { + if (data[index].complexValue != none) { + data[index].complexValue.Destroy(); + } + } data.Remove(index, amount); return true; } +public function Clear() +{ + RemoveValue(0, data.length); +} + public function bool IsSubsetOf(JSON rightValue) { local int i; diff --git a/sources/Data/JSON/JObject.uc b/sources/Data/JSON/JObject.uc index 1713a9d..fb358de 100644 --- a/sources/Data/JSON/JObject.uc +++ b/sources/Data/JSON/JObject.uc @@ -148,12 +148,17 @@ private final function UpdateProperty(JProperty newProperty) // Returns `true` if something was actually removed. private final function bool RemoveProperty(string propertyName) { - local int bucketIndex, propertyIndex; + local JProperty propertyToRemove; + local int bucketIndex, propertyIndex; // Ensure has table was initialized before any updates if (hashTable.length <= 0) { UpdateHashTableCapacity(); } if (FindPropertyIndices(propertyName, bucketIndex, propertyIndex)) { + propertyToRemove = hashTable[bucketIndex].properties[propertyIndex]; + if (propertyToRemove.value.complexValue != none) { + propertyToRemove.value.complexValue.Destroy(); + } hashTable[bucketIndex].properties.Remove(propertyIndex, 1); storedElementCount = Max(0, storedElementCount - 1); UpdateHashTableCapacity(); @@ -640,6 +645,21 @@ protected function string DisplayProperty( $ displaySettings.afterPropertyValue); } +public function Clear() +{ + local int i, j; + local array nextProperties; + for (i = 0; i < hashTable.length; i += 1) + { + nextProperties = hashTable[i].properties; + for (j = 0; j < nextProperties.length; j += 1) + { + if (nextProperties[j].value.complexValue == none) continue; + nextProperties[j].value.complexValue.Destroy(); + } + } +} + defaultproperties { ABSOLUTE_LOWER_CAPACITY_LIMIT = 10 diff --git a/sources/Data/JSON/JSON.uc b/sources/Data/JSON/JSON.uc index 80424c9..bef4dd2 100644 --- a/sources/Data/JSON/JSON.uc +++ b/sources/Data/JSON/JSON.uc @@ -103,6 +103,8 @@ struct JSONDisplaySettings var private const int MAX_FLOAT_PRECISION; +public function Clear(){} + public function JSON Clone() { return none; @@ -481,6 +483,12 @@ protected final function JStorageAtom ParseNumber(Parser parser) return newAtom; } +event Destroyed() +{ + super.Destroyed(); + Clear(); +} + defaultproperties { MAX_FLOAT_PRECISION = 4