On Smalltalk

thoughts on Smalltalk and programming in general…
  • Home
  • About
  • Good Books
  • My Squeak Image
  • Popular Posts

Squeak Smalltalk Image Maintenance

By Ramon Leon - October 31, 2006 under Programming, Smalltalk

Something I’ve learned since I’ve become a Smalltalker, is that to live in an image, one must learn to maintain the image.

I used to keep a fresh image handy and whenever things got out of whack, I’d just start over in a new image. I did this out of ignorance; I wasn’t aware of how to keep one image from collecting cruft. I’d end up with a ton of obsolete classes that I didn’t have a clue how to get rid of, or even understand how they came to be.

This happened a lot when I’d load or unload Monticello packages I’d created, usually due to hidden dependencies between packages. Eventually I learned to package my code better, and found a patch for Monticello that made dependencies actually work the way I expected them to.

I also learned about a great little tool called the PointerFinder from someone on Squeak-Dev, with which I could find all references to an object allowing me to hunt down and clean up bad refs, ridding myself of all those obsolete classes that would accumulate over time. This also taught me how those references came to be, and why they couldn’t be cleaned up automatically. This one tool finally allowed me to live in one image and just keep it clean, I rarely if ever need to start from a fresh image any more.

Ultimately, I developed my own version of #garbageCollect that I tossed into a utility class to help me maintain my image. Whenever I find some new maintenance tip to help keep my image clean and organized, I just toss it in here. The last few lines are the most interesting, either everything goes well and the image is saved, or obsolete classes are found and a PointerFinder is launched on each one forcing me to clean up those bad references right away.

Here’s what I’ve collected so far…

garbageCollect
    | tasks |
    tasks := OrderedCollection new
                add: [MCFileBasedRepository flushAllCaches];
                add: [WARegistry clearAllHandlers];
                add: [SMSqueakMap default clearCaches];
                add: [Smalltalk removeEmptyMessageCategories];
                add: [Workspace
                        allSubInstancesDo: [:each | each setBindings: Dictionary new]];
                add: [Undeclared removeUnreferencedKeys];
                add: [Categorizer sortAllCategories];
                add: [ODBCConnection cleanAll];
                add: [Symbol compactSymbolTable];
                add: [ReleaseBuilderDeveloper new fixObsoleteReferences];
                add: [Smalltalk garbageCollectMost];
                 yourself.
    Utilities
        informUserDuring: [:bar | tasks
                do: [:block |
                    bar value: block printString.
                    [block value]
                        on: Error
                        do: [:error | Transcript show: error;
                                 cr]]].
    SystemNavigation default obsoleteClasses isEmpty
        ifTrue: [SmalltalkImage current saveSession]
        ifFalse: [SystemNavigation default obsoleteClasses
                do: [:each | [PointerFinder on: each]
                        on: Error
                        do: [:error | Transcript show: error; cr]]]

Hopefully the code speaks for itself, and you can remove anything that doesn’t apply to your image. If you have any new tips that I’m unaware of, I’d love to hear about them. I’m always looking for a new trick!

I have this wired up to a hot key via KeyBinder, and simply run it once in a while to ensure everything stays nice and clean, and the image organized and small.

Tags: Smalltalk

Related posts
    at: "Popular Posts";
    at: "20 October 2007 > Squeak Image Updated";
    at: "07 December 2007 > Squeak Image Updated";

12 Comments so far

  1. Göran Krampe on November 1st, 2006

    Hi!

    I notice you use “SMSqueakMap default clearCaches”. This “nils out” the contents in the map itself - but I am hard pressed to see how that would remove any “dangling” objects since the map is totally self contained AFAIK.

    But I can be wrong. :)

  2. Ramon Leon on November 1st, 2006

    I’m not sure where I picked that one up, maybe I was just hoping it’d reduce memory use within the image for deployment purposes. I just like clean caches!

  3. Brian Brown on November 1st, 2006

    Hey Ramon, are you going to publish your Utility class somewhere? :-)

  4. Ramon Leon on November 1st, 2006

    Isn’t that what I’m doing… one post at a time. ;) Besides… you have my base image, snoop around.

  5. timbomb on November 1st, 2006

    Hey Ramon, I just wanted to thank you for taking the time to blog about Smalltalk and Seaside from the point of view of a working programmer. It’s great to see that you’re making it work, but posts like this where you’re obviously doing real stuff, not just experimenting are tremendously valuable - not just as HOWTOs for other Seaside folk, but also to reinforce the credibility of the environment.

    Summary: you rock :)

    Tim

  6. Ramon Leon on November 1st, 2006

    Thanks, I appreciate the kind words.

  7. links for 2006-11-02 at He’s Just Had Coffee on November 2nd, 2006

    [...] Squeak Smalltalk Image Maintainence | OnSmalltalk: A Squeak, Smalltalk, Seaside, Web Development Blog Ramon’s tips for maintaining a Smalltalk image over time. (tags: smalltalk programming monticello) [...]

  8. Michael Davies on January 31st, 2007

    Hi Ramon, I just found this useful bit of code while googling for an issue with obsolete classes. Thanks for publishing this. (Thanks also for your comments on my blog yesterday).

    Cheers,
    Michael

  9. Ramon Leon on January 31st, 2007

    Any time.

  10. nitin bhatia on February 23rd, 2007

    goood

  11. Warren Wilkinson on June 12th, 2007

    Thank you so much for this! I’d spent hours looking around for ways to clean up my squeak image and wasn’t getting anywhere chasing down pointers trying to find why my image was retaining several thousand database entries in memory after Seaside was terminated.

    Running this once brought my image down from 99 Megs to 26 Megs. (And the previous night my image was up to 360 Megs forcing me to revert to a previously saved image).

  12. Ramon Leon on June 12th, 2007

    You’re welcome.

Posting your comment.


  • Sponsors

  • Tags

    Databases General Linux Lisp Magritte Performance Profiling Programming Ruby Seaside Smalltalk Sql Squeak Updates
  • Categories

    • .Net (5)
    • Databases (9)
    • General (5)
    • Linux (2)
    • Lisp (3)
    • Magritte (2)
    • Programming (62)
    • Ruby (6)
    • Seaside (42)
    • Smalltalk (72)
    • Sql (2)
    • Stuff I Just Like (6)
    • Updates (7)
  • Blogs

    • (gem)Stone Soup
    • Avi Bryant
    • Boris Popov
    • defmacro
    • Giles Bowkett
    • Goran Krampe
    • James Robertson
    • Lukas Renggli
    • Martin Fowler
    • Paul Graham
    • Ralph Johnson
    • Randal Schwartz
    • Vassili Bykov
    • Weekly Squeak
  • Favorite Tools

    • Apache
    • Cygwin
    • FireFox
    • Scriptaculous
    • Seaside
    • Squeak
    • Squeak Dev Image
    • Ubuntu Linux
    • WordPress
  • Meta

    • Log in
    • Entries RSS
    • Comments RSS
    • WordPress.org

Copyright © 2008 On Smalltalk