summaryrefslogtreecommitdiff
path: root/scope.c
diff options
context:
space:
mode:
authorGurusamy Sarathy <gsar@engin.umich.edu>1997-08-07 00:00:00 +0000
committerTim Bunce <Tim.Bunce@ig.co.uk>1997-08-07 00:00:00 +1200
commitbc44cdafae83e0dac3f8fcc1b06f85be485291c6 (patch)
tree13f613e911d8114a2b0f36d02e65671a8d73e0ac /scope.c
parent9a1ce46c336d20e36c6e5d34d0167ffdb7a5cdff (diff)
downloadperl-bc44cdafae83e0dac3f8fcc1b06f85be485291c6.tar.gz
object never destructs
On Sun, 13 Jul 1997 11:20:24 EDT, Andrew Pimlott wrote: >package mytest; >sub DESTROY { warn "Death"; } >package main; >{ > my $joe; > my $moe; > $moe = bless \$joe, 'mytest'; > print "Leaving block\n"; >} >print "Left block\n"; Thanks for that excellent test case. Perl optimizes the memory management of lexicals by not actually deallocating unreferenced lexicals when the block exits, in order to reuse them when the block is reentered. This of course fails to destruct objects at the end of blocks. A patch that fixes the problem for all object datatypes is attached. p5p-msgid: 199707131955.PAA29655@aatma.engin.umich.edu
Diffstat (limited to 'scope.c')
-rw-r--r--scope.c3
1 files changed, 2 insertions, 1 deletions
diff --git a/scope.c b/scope.c
index 0487ebefbd..98d99a47a2 100644
--- a/scope.c
+++ b/scope.c
@@ -536,7 +536,8 @@ I32 base;
case SAVEt_CLEARSV:
ptr = (void*)&curpad[SSPOPLONG];
sv = *(SV**)ptr;
- if (SvREFCNT(sv) <= 1) { /* Can clear pad variable in place. */
+ /* Can clear pad variable in place? */
+ if (SvREFCNT(sv) <= 1 && !SvOBJECT(sv)) {
if (SvTHINKFIRST(sv)) {
if (SvREADONLY(sv))
croak("panic: leave_scope clearsv");