Cuis-Smalltalk / Cuis-Smalltalk-Dev

Active development of Cuis Smalltalk
MIT License
433 stars 71 forks source link

Best Practices : dealing with stubborn, unwanted object references #206

Closed gamecubate closed 2 years ago

gamecubate commented 2 years ago

To avoid dangling object references and other such troubles, I tend to use this pattern:

mm := MyMorph new openInWorld. 
MyMorph allInstances size. => 1
mm delete.
mm := nil.
MyMorph allInstances size. => 0

But I sometimes accidentally overwrite an existing binding:

mm := MyMorph new openInWorld. 
mm := MyMorph new openInWorld. 
MyMorph allInstances size. => 2
mm delete.
mm := nil.
MyMorph allInstances size. => 1

In that case, I do:

MyMorph allInstances do: [ :each | each delete ].
MyMorph allInstances size. => 0

and it works, in general.

Yet, after a few days of coding, sending #allInstances to some of my (new) classes persists in returning returns results > 0 despite my use of this last (delete all) code block. I cannot seem to get rid of them and it is quite likely that I had bound those unwanted instances to names I no longer use and have long since forgotten (I sometimes close my Workspace windows).

My question : How do you deal with such issues when you encounter them?

Thanks

nmingotti commented 2 years ago

In my opinion it would be advisable that you post your questions in the mailing list without putting theme here. Since that is what other people do. Personally, i put here only open issues or feature requests that were seen in the mailing list first.

gamecubate commented 2 years ago

Makes perfect sense. Thanks for the advice.