Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re^2: Garbage collected class attributes with inside out classes.

by kyle (Abbot)
on Mar 01, 2007 at 22:47 UTC ( [id://602801]=note: print w/replies, xml ) Need Help??


in reply to Re: Garbage collected class attributes with inside out classes.
in thread Garbage collected class attributes with inside out classes.

The documentation is correct, of course!

In my first implementation, the class attributes are declared as :ATTR, and they behave as described. That's why that implementation does not have its own DEMOLISH (called by the Class::Std DESTROY). That is, in a way, its advantage. You do your work up front in a way that the module takes care of the rest of the work at the end.

The difference between what I have declared as :ATTR and what is normally declared as :ATTR is that normally the elements of the hash are all different. Each instance has its own key and value. In my case, the values of an individual hash are all the same—one reference shared by every instance. (Each still has its own key, but they all have the same value.) I'm tricking the instance attributes into behaving as class attributes.

In the second implementation, the class attributes are not declared as :ATTR at all, so I have to clean them up myself with my own DEMOLISH.

Replies are listed 'Best First'.
Re^3: Garbage collected class attributes with inside out classes.
by eric256 (Parson) on Mar 02, 2007 at 00:22 UTC

    I think I understand now. So you are talking about having class attributes along side the instance attributes? If that is the case wouldn't you want the class attributes to exist until the program terminated in case you created a new instance after all the others where destroyed?

    This my ($other_ident) = keys %example_hash_of; is confusing me, what does that do? It would seem that its just grabbing the first key in the hash regardless of what it is.

    I have the distinct feeling I'm confusing the trees with the forest here, but I'm also determined to understand!


    ___________
    Eric Hodges

      wouldn't you want the class attributes to exist until the program terminated in case you created a new instance after all the others where destroyed?

      In many cases, I'd expect that to be true, yes. Part of my background for this, however, is that one of these class attributes holds a large data structure that I don't want to hold in memory. There could be other reasons for wanting one thing shared by all instances that you also want to deallocate when there are no more instances.

      It would seem that its just grabbing the first key in the hash regardless of what it is.

      Yes, that's exactly what it does. It finds any other instance of the same class. if there is no other instance, $other_ident will be undef. If there is some other instance, I take a copy of that instance's class attribute reference. Since they all have the same reference, it doesn't matter which one I get.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://602801]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others perusing the Monastery: (3)
As of 2024-04-26 05:56 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found