mirror of https://github.com/sveltejs/svelte
parent
425fba33fe
commit
509868bc41
@ -0,0 +1,9 @@
|
||||
---
|
||||
'svelte': patch
|
||||
---
|
||||
|
||||
fix: null out `effect.b` (boundary reference) in `destroy_effect` to prevent memory leak
|
||||
|
||||
When a dynamic component switches (e.g., `<Component />`), old branch effects are destroyed but were still retaining a reference to the `Boundary` instance via the `effect.b` field. This prevented the garbage collector from reclaiming memory for destroyed component subtrees, causing memory to grow without bound when repeatedly changing a mounted component's props.
|
||||
|
||||
Fixes #17881
|
||||
@ -0,0 +1 @@
|
||||
<p>About</p>
|
||||
@ -0,0 +1 @@
|
||||
<p>Home</p>
|
||||
@ -0,0 +1,26 @@
|
||||
import { flushSync } from 'svelte';
|
||||
|
||||
export default {
|
||||
html: '<p>Home</p>',
|
||||
|
||||
async test({ assert, target, component }) {
|
||||
// Switch to About
|
||||
component.page = 'About';
|
||||
flushSync();
|
||||
assert.htmlEqual(target.innerHTML, '<p>About</p>');
|
||||
|
||||
// Switch back to Home
|
||||
component.page = 'Home';
|
||||
flushSync();
|
||||
assert.htmlEqual(target.innerHTML, '<p>Home</p>');
|
||||
|
||||
// Rapidly switch multiple times to stress test cleanup
|
||||
for (let i = 0; i < 10; i++) {
|
||||
component.page = i % 2 === 0 ? 'About' : 'Home';
|
||||
flushSync();
|
||||
}
|
||||
|
||||
// Should end on Home (10 is even, 0-indexed last is About → Home)
|
||||
assert.htmlEqual(target.innerHTML, '<p>Home</p>');
|
||||
}
|
||||
};
|
||||
@ -0,0 +1,10 @@
|
||||
<script>
|
||||
import Home from './Home.svelte';
|
||||
import About from './About.svelte';
|
||||
let { page = 'Home' } = $props();
|
||||
|
||||
const components = { Home, About };
|
||||
let Component = $derived(components[page]);
|
||||
</script>
|
||||
|
||||
<Component />
|
||||
Loading…
Reference in new issue