<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[A.G.Deneth Mihiranga Tech]]></title><description><![CDATA[Official tech blog of A.G.Deneth Mihiranga, AI/ML Engineer & Front-End Web Developer in Sri Lanka. Articles on client-side AI, NLP, and web engineering.
]]></description><link>https://agdenethmihiranga.hashnode.dev</link><image><url>https://cdn.hashnode.com/uploads/logos/6b09d6f0e4bd63691dbb45ba/8897516d-7caf-40c5-8d62-0cb2c12c05d7.png</url><title>A.G.Deneth Mihiranga Tech</title><link>https://agdenethmihiranga.hashnode.dev</link></image><generator>RSS for Node</generator><lastBuildDate>Sun, 29 Nov 2026 20:57:23 GMT</lastBuildDate><atom:link href="https://agdenethmihiranga.hashnode.dev/rss.xml" rel="self" type="application/rss+xml"/><language><![CDATA[en]]></language><ttl>60</ttl><item><title><![CDATA[The "Ghost Memory" Bug in Modern Browsers: How Hidden RAM Leaks Silently Slow Down Your Web Apps (And How to Fix It)]]></title><description><![CDATA[Discover the hidden JavaScript closure and detached DOM memory traps silently draining browser RAM. Learn practical debugging techniques to build…]]></description><link>https://agdenethmihiranga.hashnode.dev/the-ghost-memory-bug-in-modern-browsers-how-hidden-ram-leaks-silently-slow-down-your-web-apps-and-how-to-fix-it</link><guid isPermaLink="true">https://agdenethmihiranga.hashnode.dev/the-ghost-memory-bug-in-modern-browsers-how-hidden-ram-leaks-silently-slow-down-your-web-apps-and-how-to-fix-it</guid><category><![CDATA[JavaScript]]></category><category><![CDATA[Web Development]]></category><category><![CDATA[performance]]></category><category><![CDATA[Frontend Development]]></category><dc:creator><![CDATA[A.G.Deneth Mihiranga]]></dc:creator><pubDate>Sat, 28 Nov 2026 17:45:48 GMT</pubDate><enclosure url="https://cdn.hashnode.com/uploads/covers/6b09d6f0e4bd63691dbb45ba/6fa4ef82-1574-4a77-98a6-c801aed7aa21.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Have you ever noticed that a web application feels lightning-fast when you first open it, yet after 20 minutes of clicking around, scrolling starts to stutter and your laptop fan begins spinning like a jet engine?</p>
<p>Most developers immediately blame network latency, heavy images, or slow backend APIs. <strong>They are looking in the wrong place.</strong></p>
<p>Deep inside modern web browsers, a silent performance killer is often at work—something rarely discussed in standard web development tutorials: <strong>Detached DOM Trees and "Ghost" Closure Memory Leaks.</strong></p>
<hr />
<h2>🧠 What Is "Ghost Memory" in the Browser?</h2>
<p>When you remove an HTML element from a webpage using JavaScript (for example, closing a modal, switching tabs in a Single Page Application, or deleting a list item), you expect the browser's Garbage Collector to immediately free up that memory.</p>
<p><strong>However, if even a single hidden JavaScript variable, event listener, or closure still holds a reference to that removed element, the browser refuses to delete it.</strong></p>
<p>The element disappears from your screen, yet it remains alive in your user's RAM like a ghost—along with every parent, child, and image attached to it.</p>
<hr />
<h2>⚠️ 3 Hidden Traps That Silently Drain User RAM</h2>
<h4>1. The Forgotten <code>window</code> or <code>document</code> Event Listener</h4>
<p>When you attach an event listener to a global object like <code>window</code> or <code>document</code> inside a component or view, and later remove that component without calling <code>removeEventListener()</code>, the callback function—and everything inside its scope—stays trapped in memory forever.</p>
<pre><code class="language-javascript">// ❌ THE TRAP: This listener never dies when the view closes
function initDashboardWidget() {
  const massiveDataset = new Array(500000).fill("User Analytics Data");

  window.addEventListener("resize", () =&gt; {
    console.log("Resizing widget with:", massiveDataset.length);
  });
}
</code></pre>
<h4>2. Detached DOM References in Global Variables</h4>
<p>Storing a reference to a DOM node inside a global object or cache makes debugging easy, but if you delete that node from the page without setting the variable to <code>null</code>, the entire DOM subtree stays locked in RAM.</p>
<h4>3. Uncleaned <code>setInterval</code> Timers</h4>
<p>An active <code>setInterval</code> acts as an anchor. As long as the interval is running, the Garbage Collector cannot touch any variable or DOM node referenced inside that timer callback.</p>
<hr />
<h2>🛠️ How to Catch and Eliminate Memory Leaks in 60 Seconds</h2>
<p>You don't need expensive monitoring tools to uncover these hidden leaks. Google Chrome's built-in DevTools has a superpower that most developers overlook:</p>
<ol>
<li>Open <strong>Chrome DevTools</strong> (<code>F12</code> or <code>Ctrl + Shift + I</code>) and go to the <strong>Memory</strong> tab.</li>
<li>Select <strong>Heap snapshot</strong> and click <strong>Take snapshot</strong>.</li>
<li>Use your web app for 2 minutes (open and close modals, navigate between views).</li>
<li>Click the <strong>Trash Can icon (Collect garbage)</strong>, then take a <strong>second Heap snapshot</strong>.</li>
<li>In the <strong>Class filter</strong> search bar at the top, type <code>Detached</code>.</li>
</ol>
<p>If you see entries like <code>Detached HTMLDivElement</code> or <code>Detached HTMLElement</code> piling up, you have caught a ghost memory leak red-handed!</p>
<hr />
<h2>✅ The Clean Architecture Fix (<code>AbortController</code>)</h2>
<p>Instead of manually tracking dozens of <code>removeEventListener()</code> calls, modern JavaScript gives us a remarkably clean pattern using <code>AbortController</code>:</p>
<pre><code class="language-javascript">// ✅ THE FIX: Clean up all listeners in a single line
function initDashboardWidget() {
  const controller = new AbortController();
  const { signal } = controller;

  window.addEventListener("resize", handleResize, { signal });
  document.addEventListener("keydown", handleKeyPress, { signal });

  // Call this when closing or unmounting the widget
  return () =&gt; controller.abort();
}
</code></pre>
<p>By passing <code>{ signal }</code> to your event listeners, calling <code>controller.abort()</code> instantly detaches every single listener and lets the browser's Garbage Collector wipe the memory clean.</p>
<hr />
<p><strong>💡 Final Takeaway</strong></p>
<p>Great software engineering isn't just about making features work—it's about respecting your user's hardware, battery life, and memory. The next time your web app feels sluggish after prolonged use, open the Memory tab and hunt down the ghosts.</p>
<hr />
<hr />
<p>Written by A.G. Deneth Mihiranga— AI/ML Engineer &amp; Front-End Web Developer based in Galle, Sri Lanka. Connect and explore more open-source tools and articles across my platforms:</p>
<ul>
<li>🌐 Portfolio: <a href="https://vercel.app">deneth-portfolio.vercel.app</a></li>
<li>💼 <strong>LinkedIn:</strong> <a href="https://www.linkedin.com/in/a-g-deneth-mihiranga">linkedin.com/in/a-g-deneth-mihiranga</a></li>
<li>💻 <strong>GitHub:</strong> <a href="https://github.com/gunawardhanadeneth2006-commits">github.com/gunawardhanadeneth2006-commits</a></li>
<li>📝 DEV Community: <a href="https://dev.to">dev.to/agdenethmihiranga</a></li>
</ul>
]]></content:encoded></item><item><title><![CDATA[Stop Sending User Data to Expensive AI APIs: Build a 0ms Client-Side AI Engine in Pure JavaScript]]></title><description><![CDATA[Learn how to build a zero-latency, 100% private NLP engine in pure JavaScript with $0 server costs. Complete guide & code by A.G.Deneth Mihiranga.]]></description><link>https://agdenethmihiranga.hashnode.dev/stop-sending-user-data-to-expensive-ai-apis-build-a-0ms-client-side-ai-engine-in-pure-javascript</link><guid isPermaLink="true">https://agdenethmihiranga.hashnode.dev/stop-sending-user-data-to-expensive-ai-apis-build-a-0ms-client-side-ai-engine-in-pure-javascript</guid><category><![CDATA[JavaScript]]></category><category><![CDATA[Artificial Intelligence]]></category><category><![CDATA[Web Development]]></category><category><![CDATA[Machine Learning]]></category><category><![CDATA[open source]]></category><dc:creator><![CDATA[A.G.Deneth Mihiranga]]></dc:creator><pubDate>Fri, 27 Nov 2026 20:30:17 GMT</pubDate><enclosure url="https://cdn.hashnode.com/uploads/covers/6b09d6f0e4bd63691dbb45ba/47d86ecb-9c25-4f06-b3d9-06639944ea1a.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>By A.G. Deneth Mihiranga | AI/ML Engineer &amp; Front-End Web Developer</p>
<p>Every single day, thousands of developers build AI web apps the exact same way: take user text, send it to a backend server, pay for an external API call, and make the user stare at a loading spinner for 3 seconds.</p>
<p>Here is the uncomfortable truth: For 70% of text-analysis tasks—like resume keyword matching, document scoring, or instant content filtering you don't need a backend server at all.</p>
<p>What if you could run a blazing-fast, zero-latency Natural Language Processing (NLP) engine directly inside the user's browser with: $0.00 in server or API costs 0ms network latency 100% mathematical guarantee that sensitive user data never leaves their device</p>
<p>In this deep dive, I will show you the exact architecture and production-ready JavaScript engine I used to build my open-source <a href="https://github.io">AI Resume &amp; Job Match Analyzer</a> and how you can drop this pattern into your own web apps today.</p>
<hr />
<p>Why Traditional AI Web Architectures Are Failing Modern Users</p>
<p>When a user uploads a confidential contract, a medical note, or a personal CV to a web app, sending that raw text to a third-party server creates three massive bottlenecks:</p>
<ol>
<li>The Privacy Trust Barrier: Security-conscious users and enterprise companies immediately abandon tools that transmit sensitive documents over the network.</li>
<li>The Latency Penalty: Network round-trips kill user retention. Every 500ms of delay drops user engagement dramatically.</li>
<li>The Scaling Trap: If your app goes viral overnight, a server-dependent AI wrapper will drain your wallet before you even monetize it.</li>
</ol>
<p>By shifting the intelligence to Client-Side JavaScript, your user's own CPU becomes your free, infinitely scalable cloud infrastructure.</p>
<hr />
<p>Inside the 0ms Browser NLP Engine (Step-by-Step)</p>
<p>To match a candidate's resume against a job description in real time without external libraries, we need a clean 3-stage pipeline: Tokenization, Stop-Word Filtering, and Set-Intersection Scoring.</p>
<p>Here is the exact, lightweight engine you can copy and run in any browser right now:</p>
<pre><code class="language-javascript">// 1. High-noise words that add zero semantic value
const STOP_WORDS = new Set([
  "the", "and", "is", "in", "to", "of", "a", "for", "with", "on", 
  "as", "are", "at", "be", "this", "by", "from", "or", "an", "will"
]);

// 2. Clean, normalize, and extract meaningful technical tokens
function extractKeywords(text) {
  return text
    .toLowerCase()
    .replace(/[^a-z0-9+#.\s-]/g, " ") // Preserve tech terms like C++, C#, Node.js
    .split(/\s+/)
    .filter(word =&gt; word.length &gt; 2 &amp;&amp; !STOP_WORDS.has(word));
}

// 3. Calculate real-time compatibility score &amp; skill gaps
function analyzeJobMatch(resumeText, jobDescriptionText) {
  const resumeTokens = new Set(extractKeywords(resumeText));
  const jobTokens = [...new Set(extractKeywords(jobDescriptionText))];

  if (jobTokens.length === 0) return { score: 0, matched: [], missing: [] };

  const matched = [];
  const missing = [];

  jobTokens.forEach(skill =&gt; {
    if (resumeTokens.has(skill)) {
      matched.push(skill);
    } else {
      missing.push(skill);
    }
  });

  const score = Math.round((matched.length / jobTokens.length) * 100);

  return { score, matched, missing };
}
</code></pre>
<p>Why This Pattern Works So Well: Preserves Tech Syntax: Notice the regex <code>/[^a-z0-9+#.\s-]/g</code>. Unlike naïve text cleaners that strip symbols, this keeps critical engineering terms like <code>C++</code>, <code>C#</code>, and <code>Node.js</code> intact. O(1) Lookup Speed: Converting the resume tokens into a JavaScript <code>Set</code> guarantees instant lookups, allowing the browser to process thousands of words in under 2 milliseconds.</p>
<hr />
<p>See It Live in Action</p>
<p>I packaged this architecture into a dark-mode, zero-dependency web application that helps job seekers instantly audit their CVs against Applicant Tracking Systems (ATS).</p>
<p>🚀 Test the Live App: <a href="https://github.io">AI Resume &amp; Job Match Analyzer</a></p>
<p>💻 Inspect or Fork the Source Code: <a href="https://github.com">GitHub Repository</a></p>
<hr />
<p>The Future Belongs to Hybrid AI Engineers</p>
<p>The developers who will stand out in 2026 and beyond aren't the ones blindly chaining expensive API calls together. They are the engineers who know when to use heavy cloud models and when to engineer smart, privacy-first client-side solutions.</p>
<p>If you found this architecture useful, drop a ❤️ or bookmark this guide for your next project!</p>
<p>What is one task you think developers unnecessarily use heavy backend AI for? Let’s debate in the comments below! 👇</p>
<hr />
<p>About the Author</p>
<p>A.G.Deneth Mihiranga is an AI/ML Engineer and Front-End Web Developer from Sri Lanka, certified by SLIIT, the University of Moratuwa (UoM), and Harvard University (CS50x). He builds open-source, privacy-first AI web applications.<br />🔗 Portfolio: <a href="https://sites.google.com/view/agdenethmihiranga/">https://google.com</a> | GitHub: <a href="https://github.com">@gunawardhanadeneth2006-commits</a> | linkdin:<a href="https://www.linkedin.com/in/a-g-deneth-mihiranga/">https://www.linkedin.com/in/a-g-deneth-mihiranga/</a></p>
]]></content:encoded></item></channel></rss>