Here's JavaScript code that will definitely trigger OOM in your deno_core setup:
// This will quickly consume memory by creating large arrays
const arrays = [];
let counter = 0;
while (true) {
// Create 10MB arrays filled with random data
const largeArray = new Array(1024 * 1024 * 10).fill(0).map(() => Math.random());
arrays.push(largeArray);
counter++;
console.log(`Created array ${counter}, total arrays: ${arrays.length}`);
// This will hit your heap limit very quickly
if (counter > 200) break; // Safety break (won't be reached due to OOM)
}
return "This won't be returned due to OOM";
// Exponential string growth
let str = "a";
let iteration = 0;
while (true) {
str = str + str; // Doubles the string size each iteration
iteration++;
console.log(`Iteration ${iteration}, string length: ${str.length}`);
// Will OOM before reaching iteration 30
if (iteration > 30) break;
}
return str.length;
// Create millions of objects
const objects = [];
let count = 0;
while (true) {
// Create objects with random properties
const obj = {
id: count,
data: new Array(1000).fill(0).map(() => ({
value: Math.random(),
timestamp: Date.now(),
nested: {
more: "data".repeat(100),
array: new Array(100).fill(Math.random())
}
}))
};
objects.push(obj);
count++;
if (count % 1000 === 0) {
console.log(`Created ${count} objects`);
}
// Safety break (won't be reached)
if (count > 1000000) break;
}
return objects.length;
// Create large ArrayBuffers
const buffers = [];
let totalSize = 0;
while (true) {
// Create 50MB buffer
const size = 50 * 1024 * 1024;
const buffer = new ArrayBuffer(size);
const view = new Uint8Array(buffer);
// Fill with data to ensure allocation
for (let i = 0; i < view.length; i += 1024) {
view[i] = Math.floor(Math.random() * 256);
}
buffers.push(buffer);
totalSize += size;
console.log(`Total allocated: ${Math.round(totalSize / 1024 / 1024)} MB`);
// This will definitely OOM with your limits
if (totalSize > 2 * 1024 * 1024 * 1024) break; // 2GB safety
}
return totalSize;
With your current settings:
MAX_HEAP_SIZE: 50 MB
→HEAP_SIZE_INCREASE_LIMIT: 512 MB
Any of these scripts will:
- Trigger
near_heap_limit_callback
multiple times - Log warnings about reaching heap limits
- Eventually call
isolate.terminate_execution()
- Trigger the
oom_handler
- Return a JavaScript execution error
Start with the Array Allocation example as it's the most predictable and will hit your limits fastest. You should see your tracing logs showing heap limit warnings before the OOM occurs.
The exact point of failure will depend on your current heap settings, but with 50MB initial limit growing to 512MB max, these scripts will definitely cause OOM.