Am 15.07.2008 um 13:23 schrieb nicolas cellier: > Bert Freudenberg a écrit : >> Am 15.07.2008 um 08:26 schrieb Herbert König: >>> Hello Randal, >>> >>> RLS> dictionary. This is how the classic "dependents" system >>> works as well: the >>> RLS> dependencies are in a WeakDictionary so that when the watched >>> object goes >>> RLS> away, the dependencies are also cleaned. >>> >>> thanks for some free education (no smiley, I mean it), now I'll do >>> some homework and look up dependency. >>> >>> I use it in some places without knowing of it's "weakness". >> The dependents are weak only for "regular" objects. Proper Models >> handle their own dependents collection in a non-weak manner. >> - Bert - > > Hmm, not really > > "Warning: this example is stupid!" > | tmp | > tmp := Model new. > tmp addDependent: #x. > tmp addDependent: #y. > tmp dependents class. "=> DependentsArray" > > DependentsArray is a class that holds weakly to its elements... > > The difference is that the DependentsArray itself don't have to > pollute the global WeakIdentityKeyDictionary (Object classPool at: > #DependentsFields). You are right, I was mislead by Object>>dependents ... > But maybe we have just quit the beginners rails... ... and you are right again. - Bert - _______________________________________________ Beginners mailing list [hidden email] http://lists.squeakfoundation.org/mailman/listinfo/beginners |
Bert Freudenberg a écrit :
> > Am 15.07.2008 um 13:23 schrieb nicolas cellier: > >> Bert Freudenberg a écrit : >>> The dependents are weak only for "regular" objects. Proper Models >>> handle their own dependents collection in a non-weak manner. >>> - Bert - >> >> Hmm, not really >> >> "Warning: this example is stupid!" >> | tmp | >> tmp := Model new. >> tmp addDependent: #x. >> tmp addDependent: #y. >> tmp dependents class. "=> DependentsArray" >> >> DependentsArray is a class that holds weakly to its elements... >> >> The difference is that the DependentsArray itself don't have to >> pollute the global WeakIdentityKeyDictionary (Object classPool at: >> #DependentsFields). > > You are right, I was mislead by Object>>dependents ... > >> But maybe we have just quit the beginners rails... > > > ... and you are right again. > > - Bert - While we are at it, here is a lesson i learned recently: | weak obj | weak := WeakIdentityKeyDictionary new. "Create an Object" obj := Object new. "Add a weak reference to this Object" weak at: obj put: (Array with: obj). "This DoIt methods points to the Object via it's temporary variable. Clear this pointer, so that the Object can eventually be reclaimed" obj := nil. "Now garbageCollect to reclaim the weak references" Smalltalk garbageCollect. "Let us see if the Object was reclaimed:" ^weak size Why the object obj was not reclaimed? Obviously, the WeakKeyAssociation value is not weak... It is a strong pointer and points strongly to obj through the Array... Trivial, you might say. Well yes, it is just http://bugs.squeak.org/view.php?id=7119 in disguise and i find it nasty. So be very carfull with Weak references - not only newbs - issues might definitely be advanced to track down... Nicolas _______________________________________________ Beginners mailing list [hidden email] http://lists.squeakfoundation.org/mailman/listinfo/beginners |
In reply to this post by Nicolas Cellier-3
>>>>> "nicolas" == nicolas cellier <[hidden email]> writes:
nicolas> But maybe we have just quit the beginners rails... I think the moment you mention "Weak", you're already outside beginner space. :) -- Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095 <[hidden email]> <URL:http://www.stonehenge.com/merlyn/> Smalltalk/Perl/Unix consulting, Technical writing, Comedy, etc. etc. See http://methodsandmessages.vox.com/ for Smalltalk and Seaside discussion _______________________________________________ Beginners mailing list [hidden email] http://lists.squeakfoundation.org/mailman/listinfo/beginners |
Randal L. Schwartz a écrit :
>>>>>> "nicolas" == nicolas cellier <[hidden email]> writes: > > nicolas> But maybe we have just quit the beginners rails... > > I think the moment you mention "Weak", you're already outside > beginner space. :) > That's the quality of our Squeak beginners. They bring really advanced topics to this list. _______________________________________________ Beginners mailing list [hidden email] http://lists.squeakfoundation.org/mailman/listinfo/beginners |
On Tue, Jul 15, 2008 at 5:47 PM, nicolas cellier <[hidden email]> wrote: Randal L. Schwartz a écrit : Well, I asked the question in the first place because the minute you try to do something "real," you run into, well, real problems that always seem to have an "advanced" answer!
I always figure that points to my true beginner-ness, though! Thanks for all the theory... Rob
_______________________________________________ Beginners mailing list [hidden email] http://lists.squeakfoundation.org/mailman/listinfo/beginners |
In reply to this post by Nicolas Cellier-3
On Tue, 15 Jul 2008 23:21:17 +0200, nicolas cellier wrote:
... > While we are at it, here is a lesson i learned recently: > > | weak obj | > weak := WeakIdentityKeyDictionary new. > "Create an Object" > obj := Object new. > "Add a weak reference to this Object" > weak at: obj put: (Array with: obj). > "This DoIt methods points to the Object via it's temporary variable. > Clear this pointer, so that the Object can eventually be reclaimed" > obj := nil. > "Now garbageCollect to reclaim the weak references" > Smalltalk garbageCollect. > "Let us see if the Object was reclaimed:" > ^weak size > > Why the object obj was not reclaimed? Perhaps because WeakIdentityKeyDictionary (as well as WeakKeyDictionary) instance variable is not initialized/assigned, as its name suggests something Weak* ;) Do (WeakIdentityKeyDictionary new inspect) and check for Weak* things: none here. This is so in the .image version that I'm using right now, 'Squeak3.10.2', haven't checked others. > Obviously, the WeakKeyAssociation value is not weak... > It is a strong pointer and points strongly to obj through the Array... Or it's just a Weak* instance variable bug :( anybody confirm this? > Trivial, you might say. > Well yes, it is just http://bugs.squeak.org/view.php?id=7119 in disguise > and i find it nasty. > > So be very carfull with Weak references - not only newbs - issues might > definitely be advanced to track down... > > Nicolas _______________________________________________ Beginners mailing list [hidden email] http://lists.squeakfoundation.org/mailman/listinfo/beginners |
Free forum by Nabble | Edit this page |