DependentsArray size and subscript is out of bounds
nicolas cellier
ncellier at ifrance.com
Wed Jul 19 23:51:35 UTC 2006
Le Jeudi 20 Juillet 2006 00:38, mathieu a écrit :
> Hi,
>
> It is normal that:
>
> (DependentsArray new: 100) size
>
> return 0?
Yes
> If yes so why?
DependentsArray count only non nil elements
> And if I do:
> | o |
>
> o := WriteStream on: (DependentsArray new: 100).
> 1 to: 24 do: [:each | o nextPut: Object new]. "do it sevral time"
>
> it raise an error 'subscript is out of bounds: 22' from time to time
> why?
You cannot do that with DependentsArray.
DependentsArray are weak array: that mean that storing an object into a
DependentsArray does not prevent it from being garbageCollected.
When an element is garbage collected, corresponding index in DependentsArray
is replaced by nil.
All is occuring in pastEndPut:
Since initial size (non nil elements) is zero, then the array is grown to
size: oldSize + ((oldSize max: 20) min: 1000000)
When no garbageCollection occurs, that works fine (except a new
DependentsArray is created each time you add an Object).
When a garbage collect occurs, all unreferenced (Object new) are removed from
the DependentsArray, except one (I do not know who is referencing it, maybe
the BlockContext...).
Thus you allocate a DependentsArray of size 21 and fail when storing element
number 22...
> Thx
> Math
What do you need DependentsArray for?
Nicolas
More information about the Squeak-dev
mailing list
|