diff --git a/Source/Array.m b/Source/Array.m index 6e6fdde06..c073ead34 100644 --- a/Source/Array.m +++ b/Source/Array.m @@ -195,6 +195,7 @@ - appendElement: (elt)newElement { incrementCount(self); + RETAIN_ELT(newElement); _contents_array[_count-1] = newElement; return self; } @@ -202,6 +203,7 @@ - prependElement: (elt)newElement { incrementCount(self); + RETAIN_ELT(newElement); makeHoleAt(self, 0); _contents_array[0] = newElement; return self; @@ -211,6 +213,7 @@ { CHECK_INDEX_RANGE_ERROR(index, _count+1); incrementCount(self); + RETAIN_ELT(newElement); makeHoleAt(self, index); _contents_array[index] = newElement; return self; @@ -227,7 +230,7 @@ ret = _contents_array[index]; fillHoleAt(self, index); decrementCount(self); - return ret; + return AUTORELEASE_ELT(ret); } /* We could be more efficient if we override these also. @@ -240,9 +243,10 @@ elt ret; CHECK_INDEX_RANGE_ERROR(index, _count); + RETAIN_ELT(newElement); ret = _contents_array[index]; _contents_array[index] = newElement; - return ret; + return AUTORELEASE_ELT(ret); } - swapAtIndeces: (unsigned)index1 : (unsigned)index2 diff --git a/Source/Bag.m b/Source/Bag.m index bc0ac995e..389d8fc18 100644 --- a/Source/Bag.m +++ b/Source/Bag.m @@ -81,6 +81,8 @@ else coll_hash_add(&_contents_hash, newElement, count); _count += count; + while (count--) + RETAIN_ELT(newElement); return self; } @@ -120,7 +122,9 @@ coll_hash_remove(_contents_hash, oldElement); } _count -= count; - return oldElement; + while (count-- > 0) + RELEASE_ELT(oldElement); + return AUTORELEASE_ELT(oldElement); } - (elt) removeElement: (elt)oldElement ifAbsentCall: (elt(*)(arglist_t))excFunc @@ -136,6 +140,8 @@ _count = 0; while ((node = coll_hash_next(_contents_hash, &state))) { + while ((node->value.unsigned_int_u)-- > 0) + RELEASE_ELT(node->key); node->value.unsigned_int_u = 1; _count++; }