TGViewer
JavaScript JavaScript @javascript · 31.1K subscribers
Post #2478 4.48K
CHALLENGE

const memoryLeak = () => {
const cache = new Map();
const weakCache = new WeakMap();

const objKey = { id: 123 };
const data = { name: 'User data', value: 42 };

cache.set(objKey, data);
weakCache.set(objKey, data);

// Simulate removing reference to key
const result = { map: cache.has(objKey), weakMap: weakCache.has(objKey) };
// objKey = null; // This would be an error, as const can't be reassigned

return result;
};

console.log(memoryLeak());
  • ❤ 8
  • 🤔 2
More from @javascript
  1. Oct 5, 2026Post #3539
  2. Oct 5, 2026CHALLENGE class Base { static log = []; static { Base.log.push('base-block'); } static val…
  3. Oct 4, 2026👀 Size Limit: A JavaScript Performance Budgeting Tool Set a size or load-time budget for…
  4. Oct 4, 2026Post #3536
  5. Oct 4, 2026CHALLENGE const compose = (...fns) => fns.reduce((f, g) => (...args) => f(g(...args))); co…
  6. Oct 3, 2026🤩 The Grand Unifying Architecture of Frontend SolidJS's creator argues that HTMX, React,…
Threads Profile ViewerView any public Threads profile without an account.Open ThreadLook →Writing with AI? Make it sound human.Metric37 rewrites AI drafts so they read naturally. Free AI detector, 1,500 words free.Try Metric37 →