frontpage.
newsnewestaskshowjobs

Made with ♥ by @iamnishanth

Open Source @Github

Open in hackernews

Helpful function to find memory leaks in JavaScript

1•EGreg•10h ago
I had a tough time understanding where memory leaks are coming from, especially on iOS safari. I'd go into Dev Tools > Timelines tab and see the memory go up, but not sure how or where. So I wrote this function to traverse all the global objects that have been added by various software, avoiding revisiting the same objects more than once. The function is async so as not to tie up the UX too much. You can run it to start seeing where the references are being leaked.

  Q = {};

  Q.globalNames = Object.keys(window); // snapshot baseline

  Q.globalNamesAdded = function () {
   const current = Object.keys(window);
   const baseline = Q.globalNames;
   const added = [];
  
   for (let i = 0; i < current.length; i++) {
    if (!baseline.includes(current[i])) {
     added.push(current[i]);
    }
   }
   return added;
  };
  
  Q.walkGlobalsAsync = function (filterFn, options = {}) {
    const seen = new WeakSet();
    const found = new Set();
    const pathMap = new WeakMap();

    const maxDepth = options.maxDepth || 5;
    const includeStack = options.includeStack || false;
    const logEvery = options.logEvery || 100;
    const startingKeys = Q.globalNamesAdded
      ? Q.globalNamesAdded()
      : Object.keys(window);

    let totalChecked = 0;
    let matchesFound = 0;

    function walk(obj, path = 'window', depth = 0) {
      if (!obj || typeof obj !== 'object') return;
      if (seen.has(obj)) return;
      seen.add(obj);

      totalChecked++;
      if (totalChecked % logEvery === 0) {
        console.log(`Checked ${totalChecked} objects, found ${matchesFound}`);
      }

      if (filterFn(obj)) {
        found.add(obj);
        matchesFound++;
        if (includeStack) {
          pathMap.set(obj, path);
          console.log(`[FOUND] ${path}`, obj);
        } else {
          console.log(`[FOUND]`, obj);
        }
      }

      if (depth >= maxDepth) return;

      const skipKeys = obj instanceof HTMLElement
        ? new Set([
            'parentNode', 'parentElement', 'nextSibling', 'previousSibling',
            'firstChild', 'lastChild', 'children', 'childNodes',
            'ownerDocument', 'style', 'classList', 'dataset',
            'attributes', 'innerHTML', 'outerHTML',
            'nextElementSibling', 'previousElementSibling'
          ])
        : null;

      for (const key in obj) {
        if (skipKeys && skipKeys.has(key)) continue;
        try {
          walk(obj[key], path + '.' + key, depth + 1);
        } catch (e) {}
      }
    }

    let i = 0;
    function nextBatch() {
      const batchSize = 10;
      const end = Math.min(i + batchSize, startingKeys.length);

      for (; i < end; i++) {
        try {
          walk(window[startingKeys[i]], 'window.' + startingKeys[i], 0);
        } catch (e) {}
      }

      if (i < startingKeys.length) {
        setTimeout(nextBatch, 0); // Schedule next batch
      } else {
        console.log(`Done. Found ${matchesFound} retained objects.`);
        if (includeStack) {
          console.log([...found].map(obj => ({
            object: obj,
            path: pathMap.get(obj)
          })));
        } else {
          console.log([...found]);
        }
      }
    }

    nextBatch();
  };
Here is how you use it:

  Q.walkGlobalsAsync(
   obj => obj instanceof HTMLElement && !document.contains(obj),
   { includeStack: true, maxDepth: 4, logEvery: 50 }
  );
However -- note that this will NOT find objects retained by closures, even if you can find the closures themselves you're going to have to check their code manually.

AI Cloned a Trending Mobile Game (Sand Blast Puzzle) for Web in Hours

https://sandblastgame.com
1•Kevin_Guo•29s ago•1 comments

My 9-week unprocessed food self-experiment

https://dynomight.net/unprocessed-food/
1•crescit_eundo•1m ago•0 comments

An Underwater Fossil Find Includes Remains from Ancient Human Ancestors

https://www.smithsonianmag.com/smart-news/a-massive-underwater-fossil-find-includes-remains-from-ancient-human-ancestors-180986957/
1•Brajeshwar•1m ago•0 comments

Dams around the world hold so much water they've shifted Earth's poles

https://www.livescience.com/planet-earth/dams-around-the-world-hold-so-much-water-theyve-shifted-earths-poles-new-research-shows
1•Brajeshwar•1m ago•0 comments

Bribe or community benefit? Sweeteners for renewables need to be done right

https://theconversation.com/bribe-or-community-benefit-sweeteners-smoothing-the-way-for-renewables-projects-need-to-be-done-right-258903
1•PaulHoule•4m ago•0 comments

ping.sx: Ping/MTR endpoints online from multiple worldwide regions

https://ping.sx/mtr
1•indigodaddy•7m ago•0 comments

Seven Engineers Suspended After $2.3M Bridge Includes 90-Degree Turn

https://www.vice.com/en/article/7-engineers-suspended-after-2-3-million-bridge-includes-bizarre-90-degree-turn/
5•_sbl_•9m ago•0 comments

Most engineering teams (90%) now use AI coding tools – what's next?

https://www.businessinsider.com/ai-coding-tools-popular-github-gemini-code-assist-cursor-q-2025-7
1•logic_node•9m ago•0 comments

Show HN: RunPy – simple desktop app for tinkering with Python

https://runpy.app
1•lukehaas•13m ago•0 comments

AI Tooling, Evolution and the Promiscuity of Modern Developers

https://redmonk.com/sogrady/2025/07/09/promiscuity-of-modern-developers/
1•ulrischa•15m ago•0 comments

Show HN: A Chrome Extension to Reveal SaaS Sprawl, Shadow IT, and Waste

https://www.hapstack.com/
1•rwgreen•17m ago•0 comments

Graphical Linear Algebra

https://graphicallinearalgebra.net/
2•hyperbrainer•17m ago•0 comments

One Reason Typeclasses Are Useful (2011)

https://coalton-lang.github.io/20211212-typeclasses/
1•asplake•18m ago•0 comments

Leading your engineers towards an AI-assisted future

https://blog.thepete.net/blog/2025/06/26/leading-your-engineers-towards-an-ai-assisted-future/
1•ulrischa•18m ago•0 comments

Russia, hotbed of cybercrime, says nyet to ethical hacking bill

https://www.theregister.com/2025/07/10/russia_ethical_hacking_bill/
2•rntn•18m ago•1 comments

Show HN: Trim Transformer: A transformer for physics models

https://github.com/eg-trim/trim-transformer
1•emanuelgordis•19m ago•0 comments

Index academic papers and extract metadata for AI agents

https://cocoindex.io/blogs/academic-papers-indexing/
1•badmonster•19m ago•1 comments

AWS Challenges – Verifying the Rust standard library

https://model-checking.github.io/verify-rust-std/intro.html
1•febin•19m ago•0 comments

Being a Script

https://raphaelbastide.com/etre-script/en.html
1•tarball•22m ago•0 comments

Musk unveils Grok 4 as xAI's new AI model that beats OpenAI and Google

https://the-decoder.com/musk-unveils-grok-4-as-xais-new-ai-model-that-beats-openai-and-google-on-major-benchmarks/
1•thm•23m ago•0 comments

Looking for two builders (preferably) to share apartment with

1•rtxone•24m ago•0 comments

Show HN: We built a Competitor Finder AI for early-stage startups

https://www.inodash.com/competitor-analysis-ai
1•mutlusakar•25m ago•0 comments

Grok AI to be available in Tesla vehicles next week, Musk says

https://www.reuters.com/business/autos-transportation/grok-ai-be-available-tesla-vehicles-next-week-musk-says-2025-07-10/
1•voxadam•27m ago•0 comments

Maya Ruler's Tomb Is Unearthed in Belize, with Clues to His Ancient World

https://www.nytimes.com/2025/07/10/world/americas/maya-tomb-caracol-belize.html
1•walterbell•27m ago•0 comments

Pentagon to become largest shareholder in rare earth miner MP Materials

https://www.cnbc.com/2025/07/10/pentagon-to-become-largest-shareholder-in-rare-earth-magnet-maker-mp-materials.html
2•voxadam•29m ago•0 comments

Show HN: Pg-when– psql extension for creating time values with natural language

https://github.com/frectonz/pg-when
2•jossephus01•31m ago•0 comments

CoverDrop: Blowing the Whistle Through a News App

https://www.coverdrop.org/
1•todsacerdoti•32m ago•0 comments

Ask HN: Engineering hiring managers, what do you consider a good cover letter?

1•fnord77•37m ago•1 comments

Why Did Cars Get So Hard to See Out Of?

https://www.bloomberg.com/news/articles/2025-07-10/why-did-cars-get-so-hard-to-see-out-of-blame-the-a-pillars
4•upofadown•40m ago•0 comments

Rudy: A Toolchain for Rust Debuginfo

https://www.samjs.io/blog/rudy
2•samjs•42m ago•0 comments