Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re: How to explicitly destroy an object so that all other references to it would become false?

by bdimych (Monk)
on Feb 21, 2008 at 12:30 UTC ( #669259=note: print w/replies, xml ) Need Help??


in reply to How to explicitly destroy an object so that all other references to it would become false?

1)
Many thanks!

2)
>do you have an example?

package XXX; my %already_created_objects; sub new { my ($class, $X) = @_; if (!$already_created_objects{$X}) { $already_created_objects{$X} = bless {somekey => $X} $class; } $already_created_objects{$X} }
somewhere inside the script
... $obj = new XXX($some_var_which_can_repeat); ... if ($some_conditions) { some_superundef $obj } ...

Scalar::Util::weaken can do what I would like, but, as I've understood, it is required to mark as "weak" every reference to the object? Indirection layer seems more handy, may be...

  • Comment on Re: How to explicitly destroy an object so that all other references to it would become false?
  • Select or Download Code

Replies are listed 'Best First'.
Re^2: How to explicitly destroy an object so that all other references to it would become false? (just 1)
by tye (Sage) on Feb 21, 2008 at 16:05 UTC
    but, as I've understood, it is required to mark as "weak" every reference to the object?

    No, the typical use would be to have only %already_created_objects contain weak references. Then normal object life-time control would take place and when an object is no longer referenced other than in %already_created_objects, that object would be destroyed and the value in %already_created_objects would transform into undef.

    If there is some reason you want to destroy the object while there are still live references to it besides %already_created_objects, then you should give more information to justify that unusual requirement.

    - tye        

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://669259]
help
Chatterbox?
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (3)
As of 2018-07-18 07:09 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    It has been suggested to rename Perl 6 in order to boost its marketing potential. Which name would you prefer?















    Results (383 votes). Check out past polls.

    Notices?