[Pharo-project] Another fixes to finalization (was Re: [update 1.2] #12161 - #12172)
siguctua at gmail.com
Sat Oct 2 23:47:51 EDT 2010
On 3 October 2010 03:13, Henrik Sperre Johansen
<henrik.s.johansen at veloxit.no> wrote:
> On 02.10.2010 19:01, Igor Stasenko wrote:
>> On 2 October 2010 19:47, Stéphane Ducasse<stephane.ducasse at inria.fr>
>>> Hi igor
>>> do you understand why the previous definition was
>>> Definitions ifNil: [Definitions := WeakIdentityKeyDictionary new.
>>> WeakArray addWeakDependent: Definitions].
>>> ^ Definitions
>> i don't. :)
>> It just a way to free memory as fast as possible.
>> But its really not worth spending so much CPU in order to save few
>> bytes of memory.
> Without registering the dict for finalization, the values won't ever be
> removed with the current implementation.
They are removed. After each package load/unload operation.
I don't see a reason to do this more often.
> Which can be somewhat hampering to performance once you have lots of
> nil-keyed elements all stashed from index 1 and onwards after a rehash.
In Pharo, weak dict knows how to reuse expired associations:
at: key put: anObject
"Set the value at key to be anObject. If key is not found, create a new
entry for key and set is value to anObject. Answer anObject."
| index element |
key isNil ifTrue:[^anObject].
index := self scanForEmpty: key.
"There should always be room."
index = 0 ifTrue: [ self error: 'No space left in dictionary' ].
element := array at: index.
element == nil
ifTrue: [self atNewIndex: index put: (WeakKeyAssociation key: key
element expired ifTrue: [ tally := tally + 1].
element key: key.
element value: anObject.
> Pharo-project mailing list
> Pharo-project at lists.gforge.inria.fr
Igor Stasenko AKA sig.
More information about the Pharo-dev