Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?

Re: when is destroy function called

by sundialsvc4 (Abbot)
on Feb 27, 2013 at 18:29 UTC ( #1020941=note: print w/replies, xml ) Need Help??

in reply to when is destroy function called

perldoc perlobj contains a definitive discussion both of destructors and of Perl’s garbage collector.   I think that the best way of thinking of both constructors and destructors is that they are “initialization” and “de-initialization” subroutines, respectively.   Of the two, destructors are less commonly used because they are less commonly required:   if there are no “unusual” storage-reference situations that might confuse the garbage collection algorithm, and no external resources to clean up, you often don’t need one.

As a rule of thumb, if you do something in the object’s constructor that is peculiar to that particular object instance and that has to be un-done, then you need to worry about defining a destructor.   But if you simply allocated a big data-structure that’s associated with the object, no worries, because the reference-count of all those things will also go to zero when the object itself does.   (Any exceptions to that rule will of course require an appropriate destructor.)

One thing that I can definitely say from very painful experience is this:   that you must never leave an ambiguous situation behind when your destructor completes.   If you “close” a socket, say, then immediately obliterate all memory of it (undef).   This is doubly true if you are indulging in fancy-pants designs involving subclasses of any sort.   Look carefully at the entire constructor and destructor sequences as your application grows.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1020941]
[Corion]: marto: Yeah - on a whim I bought two or three back then, but now that I'm comfortable with putting LineageOS on them, they are not for sale anymore ;)
[Corion]: It's a difficult thing, timing your purchases so that alternative ROMs are available and stable just when the devices go on clearance sale :)
[Corion]: Maybe I should work more on my "price monitoring" framework, or talk to friends to get historic price data for gadgets and employ Machine Learning to predict "device goes on final sale" events :)
[Corion]: That might be a fun project but I have to talk to people on how to best get at historic price data if that's available at all :D
[Corion]: Also, I'd like to avoid (well, do I?) situations like with Le Eco, who went bust and all of their devices went on sale. But they had AOSP for their device already, so that was good.
[marto]: Meh, looking at prices, I may just get a cheapo Chinese Intel and stick linux on it :/
[Corion]: marto: Prices for what? Cheapo tablets? Cheapo notebooks?
[Corion]: I think there is an Asus Chromebook that works with Linux and is quite good. $boss has it, I think, but it's still EUR 400 or so...
[Corion]: (too much IMO to give it into the hands of kids ;) )

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (6)
As of 2018-05-23 10:55 GMT
Find Nodes?
    Voting Booth?