MouseManager.stopListeners 从未移除滚轮监听器 — 通过 canvas 保留已销毁的 Game
作者: CasCray创建于 2026年7月18日更新于 2026年7月18日
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/phaser.min.js"></script>
<script>
const game = new Phaser.Game({ type: Phaser.AUTO, width: 640, height: 480 });
setTimeout(() => {
// Any surviving reference to the canvas — DevTools inspection, test
// tooling, an app-level screenshot cache — plays this role in real apps.
window.deadCanvas = game.canvas;
game.destroy(true);
setTimeout(() => {
// In the DevTools console:
// getEventListeners(window.deadCanvas)
// → { wheel: [ { listener: onMouseWheel, … } ] } ← still attached
//
// Take a heap snapshot → filter "Game" → the destroyed Phaser.Game is
// still reachable, retained via that wheel listener's closure.
console.log('destroyed — inspect getEventListeners(window.deadCanvas)');
}, 500);
}, 1000);
</script>Expected: after game.destroy(true), the canvas has no Phaser listeners, so a
…
内容来源: phaserjs/phaser