测试html如下,观察崩溃前的页面或观测console.log
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Memory Crash Test</title>
</head>
<body>
<div id="memoryInfo">Allocated 0 MB of memory</div>
<script>
const arrayOfBuffers = [];
const memoryInfoDiv = document.getElementById('memoryInfo');
function allocateMemory() {
try {
const buffer = new ArrayBuffer(10 * 1024 * 1024);
arrayOfBuffers.push(buffer);
const memoryMessage = `Allocated ${arrayOfBuffers.length * 10} MB of memory`;
console.log(memoryMessage);
memoryInfoDiv.textContent = memoryMessage;
setTimeout(allocateMemory, 100);
} catch (error) {
const errorMessage = `Failed to allocate more memory after ${arrayOfBuffers.length * 10} MB`;
console.error(errorMessage, error);
memoryInfoDiv.textContent = errorMessage;
}
}
allocateMemory();
</script>
</body>
</html>