The Artima Developer Community
Sponsored Link

Agile Buzz Forum
Things not to do

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
James Robertson

Posts: 29924
Nickname: jarober61
Registered: Jun, 2003

David Buck, Smalltalker at large
Things not to do Posted: Aug 29, 2003 2:56 PM
Reply to this message Reply

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.
Latest Agile Buzz Posts
Latest Agile Buzz Posts by James Robertson
Latest Posts From Cincom Smalltalk Blog - Smalltalk with Rants

Advertisement
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:

Smalltalk.Core defineClass: #Behavior
	superclass: #{Core.Object}
	indexedType: #none
	private: false
	instanceVariableNames: 'superclass methodDict format subclasses '
	classInstanceVariableNames: ''
	imports: ''
	category: 'Kernel-Classes'

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.

Read: Things not to do

Topic: Meltdown at Fenway Previous Topic   Next Topic Topic: Controlling THAPI threads in VW

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use