Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re: oop, variable that counts the number of objects created

by jcb (Parson)
on Jul 31, 2020 at 01:46 UTC ( [id://11120105]=note: print w/replies, xml ) Need Help??


in reply to oop, variable that counts the number of objects created

A technique I used to allow testing code to verify correct object destruction of some classes that use weak references to break cycles was something like:

package Whatever; sub new { my $class = shift; my $ob = {}; # ... { our $_total_constructed; $_total_constructed++ } bless $ob, $class } sub DESTROY { our $_total_destroyed; $_total_destroyed++ }

The test scripts can then access those package variables and verify that $Whatever::_total_constructed and $Whatever::_total_destroyed are equal at the end of a test run after the last lexical holding an object has gone out of scope.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (5)
As of 2024-04-24 07:38 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found