Skip to content

Commit 6a9bf07

Browse files
authored
Merge pull request #404 from andrew-demb/master
📦 Use WeakMap instead of SplObjectStorage to avoid memory leak
2 parents 21a1fc1 + d312a23 commit 6a9bf07

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

src/Knp/Menu/Matcher/Matcher.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@
1111
class Matcher implements MatcherInterface
1212
{
1313
/**
14-
* @var \SplObjectStorage<ItemInterface, bool>
14+
* @var \WeakMap<ItemInterface, bool>
1515
*/
16-
private \SplObjectStorage $cache;
16+
private \WeakMap $cache;
1717

1818
/**
1919
* @var iterable|VoterInterface[]
@@ -26,7 +26,7 @@ class Matcher implements MatcherInterface
2626
public function __construct($voters = [])
2727
{
2828
$this->voters = $voters;
29-
$this->cache = new \SplObjectStorage();
29+
$this->cache = new \WeakMap();
3030
}
3131

3232
public function isCurrent(ItemInterface $item): bool
@@ -36,7 +36,7 @@ public function isCurrent(ItemInterface $item): bool
3636
return $current;
3737
}
3838

39-
if ($this->cache->contains($item)) {
39+
if ($this->cache->offsetExists($item)) {
4040
return $this->cache[$item];
4141
}
4242

@@ -71,6 +71,6 @@ public function isAncestor(ItemInterface $item, ?int $depth = null): bool
7171

7272
public function clear(): void
7373
{
74-
$this->cache = new \SplObjectStorage();
74+
$this->cache = new \WeakMap();
7575
}
7676
}

0 commit comments

Comments
 (0)