Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

comment on

( [id://3333]=superdoc: 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 reply to Re: Garbage collected class attributes with inside out classes. by Anno
in thread Garbage collected class attributes with inside out classes. by kyle

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (7)
As of 2024-04-25 08:23 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found