This post originated from an RSS feed registered with Agile Buzz
by James Robertson.
Original Post: Things not to do
Feed Title: Cincom Smalltalk Blog - Smalltalk with Rants
Feed URL: http://www.cincomsmalltalk.com/rssBlog/rssBlogView.xml
Feed Description: James Robertson comments on Cincom Smalltalk, the Smalltalk development community, and IT trends and issues in general.
I posted earlier on an interesting - and nansty bug I had introduced into BottomFeeder. As it turns out, the problem I created can manifest itself in other ways. Here's what I did, each time I checked modules (and I have 151 feeds here):
subclasses := self allSubclasses.
That looks inocuous enough. Trouble was, I did it in a class method. Recall that classes are instances of their Metaclass, and descend from Class (up to Behavior). Look at the instance variables for Behavior:
One of them is 'subclasses'. So look again at what I did - each time through that loop, I made subclasses into a bigger collection, all filled with duplicates! When I looked at it in my development image, I had over 10,000 subclasses of the class in question! No wonder I was chewing memory, and no wonder iterating over the subclasses (that's what the code in question did) was taking a long time, and getting slower each time through!
Fixing it was a simple matter of changing the code to use a temp variable - problem solved. There's a larger lesson here though - look at Behaviior abd the subclasses down to Class. You don't want to use a variable that matches the name of any of those instance variables on the class side - referencing them in tools is ok, but assigning new values to them is a very bad idea. The only real hint you'll get is that you won't be prompted to declare a temp variable - but that's very, very easy to miss.
I'm looking at adding a code critic rule to flag these issues - if I get that working, I'll post an update. In the meantime, watch out for this sort of thing if you start seeing oddball behavior in an image.