KKitForma.

Language

EnglishEnglishTürkçeTurkishGuide unavailable in this language · open toolsDeutschGermanGuide unavailable in this language · open toolsEspañolSpanishGuide unavailable in this language · open toolsFrançaisFrenchGuide unavailable in this language · open toolsPortuguêsPortugueseGuide unavailable in this language · open toolsItalianoItalianGuide unavailable in this language · open toolsNederlandsDutchGuide unavailable in this language · open toolsPolskiPolishGuide unavailable in this language · open toolsРусскийRussianGuide unavailable in this language · open toolsУкраїнськаUkrainianGuide unavailable in this language · open toolsSvenskaSwedishGuide unavailable in this language · open toolsNorskNorwegianGuide unavailable in this language · open toolsDanskDanishGuide unavailable in this language · open toolsSuomiFinnishGuide unavailable in this language · open toolsČeštinaCzechGuide unavailable in this language · open toolsRomânăRomanianGuide unavailable in this language · open toolsΕλληνικάGreekGuide unavailable in this language · open toolsالعربيةArabicGuide unavailable in this language · open toolsעבריתHebrewGuide unavailable in this language · open toolsفارسیPersianGuide unavailable in this language · open toolsاردوUrduGuide unavailable in this language · open toolsहिन्दीHindiGuide unavailable in this language · open toolsবাংলাBengaliGuide unavailable in this language · open toolsதமிழ்TamilGuide unavailable in this language · open toolsతెలుగుTeluguGuide unavailable in this language · open toolsमराठीMarathiGuide unavailable in this language · open toolsગુજરાતીGujaratiGuide unavailable in this language · open tools简体中文Chinese SimplifiedGuide unavailable in this language · open tools繁體中文Chinese TraditionalGuide unavailable in this language · open tools日本語JapaneseGuide unavailable in this language · open tools한국어KoreanGuide unavailable in this language · open toolsTiếng ViệtVietnameseGuide unavailable in this language · open toolsไทยThaiGuide unavailable in this language · open toolsBahasa IndonesiaIndonesianGuide unavailable in this language · open toolsBahasa MelayuMalayGuide unavailable in this language · open toolsFilipinoFilipinoGuide unavailable in this language · open toolsKiswahiliSwahiliGuide unavailable in this language · open toolsAfrikaansAfrikaansGuide unavailable in this language · open toolsMagyarHungarianGuide unavailable in this language · open toolsБългарскиBulgarianGuide unavailable in this language · open toolsHrvatskiCroatianGuide unavailable in this language · open toolsSrpskiSerbianGuide unavailable in this language · open toolsSlovenčinaSlovakGuide unavailable in this language · open toolsSlovenščinaSlovenianGuide unavailable in this language · open toolsLietuviųLithuanianGuide unavailable in this language · open toolsLatviešuLatvianGuide unavailable in this language · open toolsEestiEstonianGuide unavailable in this language · open toolsCatalàCatalanGuide unavailable in this language · open toolsEuskaraBasqueGuide unavailable in this language · open tools
← Questions & answers

KITFORMA · EDITORIAL ANSWER

Why does replacing image previews gradually increase page memory?

KitForma editorial guide. Give an image preview one owned object URL, release the previous URL on replacement, and clear the final URL on disposal.

HTML, CSS & accessibility →

Step-by-step answer

Every createObjectURL call adds a binding. Replacing img.src alone does not release your previous binding. Save this example as an HTML file, select two images in succession, and then clear the preview. Runnable example:
html
<!doctype html>
<meta charset="utf-8">
<title>Preview cleanup</title>
<input id="files" type="file" accept="image/*">
<button id="clear" type="button">Clear preview</button>
<img id="preview" alt="Selected local image" style="max-width:240px">
<script>
const input = document.querySelector("#files");
const preview = document.querySelector("#preview");
let currentUrl;
function clearPreview() {
  preview.removeAttribute("src");
  if (currentUrl) URL.revokeObjectURL(currentUrl);
  currentUrl = undefined;
}
input.onchange = () => {
  const file = input.files[0];
  input.value = "";
  if (!file) return;
  clearPreview();
  currentUrl = URL.createObjectURL(file);
  preview.src = currentUrl;
};
document.querySelector("#clear").onclick = clearPreview;
</script>
Expected result: The second selection replaces the first image. Clear preview removes src and releases the current object URL. Repeating clear is harmless. Why it works: The input is also reset after capturing the File, so its old FileList is not retained by the control. Framework components should perform the same cleanup on unmount. Other application references to Files, Blobs or decoded images can still retain memory. Scope and checks: Browser Window context. This preview owns its URLs exclusively; do not revoke a URL another consumer still uses. Memory reclamation need not be immediate, so a heap snapshot after repeated selections is more informative than expecting the process memory meter to drop after every click. Related tools and guides: Selecting the same file twice: https://kitforma.com/en/community/questions/7aa10000-0000-4000-8000-000000003910/ Download URL lifetime: https://kitforma.com/en/community/questions/7aa10000-0000-4000-8000-000000003890/ Primary sources (reviewed 2026-10-08): W3C File API — blob URL lifetime: https://www.w3.org/TR/FileAPI/#lifeTime MDN — URL.createObjectURL resource management: https://developer.mozilla.org/en-US/docs/Web/API/URL/createObjectURL_static

Sources and verification

Sources checked:

This editorial answer was prepared by KitForma with AI assistance. It is not presented as a real member question or an independent user review. Check the sources and the result with your own file; report corrections in the discussion.

Discussion and community answers

Loading community…
KitForma

What would you like to do?