Newsgroups: comp.lang.smalltalk
Path: cantaloupe.srv.cs.cmu.edu!bb3.andrew.cmu.edu!newsfeed.pitt.edu!dsinc!spool.mu.edu!howland.reston.ans.net!blackbush.xlink.net!ins.net!heeg.de!gustav!hmm
From: hmm@gustav (Hans-Martin Mosner)
Subject: Re: VW Cleaning the Undeclared pool
Message-ID: <Du8Dy0.9Fr@heeg.de>
Sender: uucp@heeg.de
Organization: Georg Heeg Objektorientierte Systeme, Dortmund, FRG
X-Newsreader: TIN [version 1.2 PL2]
References: <9606291122.AA20957@mail.entra.se>
Date: Mon, 8 Jul 1996 15:34:47 GMT
Lines: 42

Bjornerstedt, Niklas (niklas.bjornerstedt@ENTRA.SE) wrote:
: Here is a little snippet for VisualWorks that cleans the global=20
: PoolDictionary
: Undeclared from unreferenced entries. The things that are left in Undecl=
: ared
: after executing this are bugs in your system.

: | tPool |
: tPool :=3D Undeclared species new.
: Undeclared associationsDo: :iAss |
:      (Browser allCallsOn: iAss ) size > 0
:           ifTrue:
:                tPool add: iAss
:           ifFalse:
:                Transcript show: 'Removing: ', iAss key; cr. .
: Undeclared :=3D tPool

A while ago I wrote a similar piece of code, with the difference
that I use the WeakArray mechanism to detect unreferenced Associations.
This has the advantage that it also find references that are hidden in blocks
stored in global variables (a very nice source of bugs...) and is much faster.

| array names str |
array := WeakArray withAll: Undeclared associations.
names := array collect: [:each | each key].
array do: [:each | Undeclared removeKey: each key].
ObjectMemory verboseGlobalCompactingGC.
array do: [:each | each == 0 ifFalse: [Undeclared add: each]].
names size > Undeclared size
	ifTrue: [str := WriteStream on: (String new: 100).
		names do: [:each | (Undeclared includesKey: each)
				ifFalse: [str space; print: each]].
		Transcript show: 'Removed from Undeclared :', str contents ; cr]
	ifFalse: [Transcript show: 'Nothing to clean up'; cr].
Undeclared isEmpty ifFalse: [Undeclared inspect]

Hans-Martin
--
+--- Hans-Martin Mosner -------- Senior Smalltalk Guru ---+
| These opinions are entirely ficticious.  Any similarity |
| to real opinions is purely coincidental and unintended. |
+--- <hmm@heeg.de> ------ URL:http://www.heeg.de/~hmm/ ---+
