memoscan
← all memos

Memo 0x9215c83c…6e3aa2 on Ethereum

Sconst lifeEvents = [ "I was born in a tiny town, barely on the map.", "On my first day of school, I clutched my lunchbox nervously.", "Years later, that smile gave me my first taste of puppy love.", "At graduation, I felt on top of the world, ready for anything.", "My first diner paycheck made me feel rich beyond my wildest dreams.", "Before I knew it, I was walking down the aisle, my heart racing.", "When they placed that squirming bundle in my arms, my world changed forever.", "One day, the boss surprised me with an unexpected promotion.", "At my retirement party, I realized how much I'd miss the daily grind.", "Holding my grandbaby, I saw life's whole cycle in those tiny eyes.", ]; class MemorySimulator { constructor(events) { this.Mind = new Map(); events.forEach((event) => { if (event.includes("bundle")) { this.Mind.set(event, { content: event }); } else { this.Mind.set(event, new WeakRef({ content: event })); } }); this.start(); } start() { if (this.timer) return; const tick = () => { console.clear(); console.log("My Life:"); console.log("----------------"); this.Mind.forEach((memoryRef, event) => { if (memoryRef instanceof WeakRef) { const memory = memoryRef.deref(); if (memory === undefined) { console.log("..."); this.Mind.delete(event); } else if (memory.content === null) { console.log("null"); } else { console.log(memory.content); } } else { console.log(memoryRef.content); } }); // Encourage garbage collection of random weak memories this.Mind.forEach((memoryRef, event) => { if (memoryRef instanceof WeakRef && Math.random() < 0.1) { const memory = memoryRef.deref(); if (memory && memory.content !== null) { memory.content = null; } } }); if (this.Mind.size === 1) { console.log("But the most important remains..."); this.stop(); } }; tick(); this.timer = setInterval(tick, 1000); } stop() { if (this.timer) { clearInterval(this.timer); this.timer = 0; } } } const simulator = new MemorySimulator(lifeEvents); function createMemoryPressure() { let array = new Array(10000000).fill("force gc"); array = null; for (let i = 0; i < 10; i++) { let obj = {}; for (let j = 0; j < 100000; j++) { obj["key" + j] = "value" + j; } obj = null; } } setInterval(createMemoryPressure, 10000);