Skip to content

Commit 1eb2b83

Browse files
authored
Allow immediate gc of ContextStorageNodes after ::detach() (#1585)
Use dummy object instead of self references as detached-marker to avoid relying on gc cycle collection. Resolves #1584.
1 parent 5f55304 commit 1eb2b83

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

ContextStorageNode.php

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,15 +52,18 @@ public function detach(): int
5252
$flags |= ScopeInterface::INACTIVE;
5353
}
5454

55+
static $detached;
56+
$detached ??= (new \ReflectionClass(self::class))->newInstanceWithoutConstructor();
57+
5558
if ($this === $this->head->node) {
56-
assert($this->previous !== $this);
59+
assert($this->previous !== $detached);
5760
$this->head->node = $this->previous;
58-
$this->previous = $this;
61+
$this->previous = $detached;
5962

6063
return $flags;
6164
}
6265

63-
if ($this->previous === $this) {
66+
if ($this->previous === $detached) {
6467
return $flags | ScopeInterface::DETACHED;
6568
}
6669

@@ -71,7 +74,7 @@ public function detach(): int
7174
assert($n->previous !== null);
7275
}
7376
$n->previous = $this->previous;
74-
$this->previous = $this;
77+
$this->previous = $detached;
7578

7679
return $flags | ScopeInterface::MISMATCH | $depth;
7780
}

0 commit comments

Comments
 (0)