in reply to Re^3: Writing a REAL destructor
in thread Writing a REAL destructor

You are indeed wrong. undef is not a garantee an object will be DESTROYed. It will only be destroyed if the ref counter goes to 0.

Image some code like this:

{ my $obj = Harf -> new; my $obj2 = $obj; undef $obj; # Does *not* call DESTROY! .... } # Only here DESTROY is called, as also $obj2 goes out of scope.

Abigail

Replies are listed 'Best First'.
Re^2: Writing a REAL destructor
by Aristotle (Chancellor) on Jun 05, 2002 at 16:35 UTC
    That is not what I meant, however; I didn't expect I came across as saying objects with a ref counter != 0 can be garbage collected. What I was saying is that as far as I know, when the ref count goes to 0, the object may not be swept right away; while if you bring the ref count down to 0 explicitly with an undef on the last reference, then it will be collected immediately.

    Makeshifts last the longest.

      What I was saying is that as far as I know, when the ref count goes to 0, the object may not be swept right away; while if you bring the ref count down to 0 explicitly with an undef on the last reference, then it will be collected immediately.

      What do you mean? First you say that if the ref count goes to 0, the object may not be swept right away (which isn't true - this is perl5, not perl6 nor Java), but if you undef the last reference, the ref count goes to 0 and it gets destroyed.

      That doesn't make any sense. Either the object is collected if the ref count goes to 0, or it isn't. But how the ref count goes to 0 doesn't matter.

      But in perl5, the object is collected right after the ref count goes to 0.

      Abigail

        Assuming Perl5 behaved like Java does and Perl6 apparently will, it would have made sense to have a way to force them to. Of course in the context of knowing that objects do get collected as soon as possible, it doesn't make sense. I was assuming the former, so it does make sense; which doesn't change the fact that it's wrong, after all.

        Somehow this reminds me of Lewis Carrol..
        If it was so, it might be; and if it were so, it would be; but as it isn't, it ain't. That's logic.
        ____________
        Makeshifts last the longest.