Strange behaviour of 'WeakArray finalization process'

Andreas Raab andreas.raab at gmx.de
Thu Nov 11 18:07:44 UTC 2004


Lukas,

I've seen this problem myself. It is easiest to see what happens when you 
have a process browser open and turn on the cpu watcher - this will show 
that the finalization process takes a huge amount of resources.

But why? Most likely (this was the case I have experienced) you have created 
some weak collection with what I consider "automatic finalization", e.g., 
WeakRegistry and friends register themselves to get notified when a weak 
references got freed. If this registry grows very large it can take 
significant amounts of time to do the finalization and if your code is then 
weak reference heavy you may spend a lot of time in finalization.

Here is an example illustration the problem:
| hog proc |
hog := WeakIdentityKeyDictionary new.
CompiledMethod allInstancesDo:[:cm| hog at: cm put: 42.0].
Smalltalk at: #CPUHog put: hog.
WeakArray addWeakDependent: hog.

"keep the finalization process busy"
proc := [
 ww := WeakArray new: 1.
 ww at: 1 put: Object new.
 Smalltalk garbageCollectMost.
] forkAt: Processor userBackgroundPriority.

Now watch the CPU usage of the finalization process in the process browser 
(on my system it's in the 10-20% range).

The solution? Don't do it. Don't use automatic finalization for large 
collections. Do it manually every now and then, for example, having a timer 
process which looks over the elements (this might get triggered by a signal 
from the finalization process btw).

Cheers,
  - Andreas

----- Original Message ----- 
From: "Lukas Renggli" <renggli at iam.unibe.ch>
To: "The general-purpose Squeak developers list" 
<squeak-dev at lists.squeakfoundation.org>
Sent: Thursday, November 11, 2004 7:16 AM
Subject: Re: Strange behaviour of 'WeakArray finalization process'


> Hi,
>
> to give some more information about the WeakArray finalization problem,
> here is a screenshot of a profiling-session in a 80 MB image running a
> big Seaside application:
>
>


--------------------------------------------------------------------------------






--------------------------------------------------------------------------------


>
>
> As far as I understand this means that during those 10 seconds we ran
> MessageTally, the finalization process bruned cpu cycles during 7
> seconds. There must be definitely something wrong, because we observed
> even stranger cases where ALL the cycles were spent there and the image
> became unresponsive. Of course we were not able to profile those, but
> this one is close and should give you a better idea about the problem.
>
> Any ideas?
>
> Thanks any hints,
> Lukas
>
> -- 
> Lukas Renggli
> http://www.lukas-renggli.ch


--------------------------------------------------------------------------------


>
> 




More information about the Squeak-dev mailing list