Hi, guys:
My son has been programming a game in Morphic and has come across the following problem.
He wants to use allInstances to do stuff, like so:
myObjectClass allInstances do: [:o | o doStuff].
The problem he's having is that he's got orphaned objects from experimenting, and he can't get rid of them. They're sketchmorphs. If I add them to the world, they'll show up, and I can then delete them with the "X" but they simply vanish from the world, while persisting.
How do I find out what is referring to these objects and thus keeping them alive?
===Blake===
Blake wrote:
The problem he's having is that he's got orphaned objects from experimenting, and he can't get rid of them. They're sketchmorphs. If I add them to the world, they'll show up, and I can then delete them with the "X" but they simply vanish from the world, while persisting.
How do I find out what is referring to these objects and thus
keeping them alive?
Hi Blake,
This page
http://wiki.squeak.org/squeak/2176
goes into great detail on how to clean up spurious objects.
My suspicion is that merely doing
Smalltalk garbageCollect.
will correct the problem.
However, this will, in general, be an issue with using "someClass allInstances" to do stuff. If what he want to do is perform some action on all *living* morphs of some type, try:
World allMorphs select: [:m | m isKindOf: someMorphicClass]
This will return a collection of all morphs who are instances of *someMorphicClass*, upon which he can then operate.
Hope this helps.
Hello Blake,
B> The problem he's having is that he's got orphaned objects from B> experimenting, and he can't get rid of them. They're sketchmorphs. If I B> add them to the world, they'll show up, and I can then delete them with B> the "X" but they simply vanish from the world, while persisting.
start with: Smalltalk garbageCollect. Smalltalk forgetDoIts then myObjectClass allInstances inspect
You get an inspector on an array, there you right click on every entry, choosing "objects pointing to this value".
You get another array whose elements you have to inspect. Every Ivar that points to a myObjectClass has to be set to in the inspector.
Sometimes they don't let you, then it might help to: myIvar: nil in the inspector.
Also on the Swiki search for "cleaning up junk".
Happy hunting!
A tip from the sidelines:
myObjectClass allInstances do: [:o | o doStuff]. takes a long time.
If you know the container, submorphs and checking for the class might prove much faster.
Cheers
Herbert mailto:herbertkoenig@gmx.net
Oops,
HK> You get another array whose elements you have to inspect. Every Ivar HK> that points to a myObjectClass has to be set to in the inspector.
it has to be set to nil :-)
Cheers
Herbert mailto:herbertkoenig@gmx.net
beginners@lists.squeakfoundation.org