Do you know where your variables are? | |
PerlMonks |
Re: Garbage collected class attributes with inside out classes.by Anno (Deacon) |
on Mar 01, 2007 at 17:44 UTC ( [id://602730]=note: print w/replies, xml ) | Need Help?? |
Interesting concept. I have never wanted to garbage-collect class variables, but I see how the need can arise.
So in your first implementation the class variables are essentially just extra attributes. Smoke, mirrors, and an additional level of indirection take care that all objects see the same shared data structure. About the second implementation (which I spontaneously like more for its simplicity) you say What's bad: There's an extra variable that you can't get rid of but also isn't part of the core functionality. Well, you just might get rid of the extra variable. Looking at the hash that implements a standard attribute, the normal course of things is that every object creates a new key on initializatiation which stays around until the object is collected. Thus scalar keys %hash is the count of objects that have been initialized in the class. Any such hash could replace the dedicated counter variable. Unless the class does things like delete entries from the hash at will, but that's unusual, and probably cruel. Anno
In Section
Meditations
|
|