Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 700453
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T03:29:59+00:00 2026-05-14T03:29:59+00:00

I am trying to figure out certain memory leak conditions in javascript on a

  • 0

I am trying to figure out certain memory leak conditions in javascript on a few browsers. Currently I’m only testing FF 3.6, Opera 10.10, and Safari 4.0.3. I’ve started with a fairly simple test, and can confirm no memory leaks in Firefox and Safari. But Opera just takes memory and never gives it back. What gives? Here’s the test:

<html>
<head>
<script type="text/javascript">
window.onload = init;
//window.onunload = cleanup;
var a=[];
function init() {
  var d = document.createElement('div');
  d.innerHTML = "page loading...";
  document.body.appendChild(d);

  for (var i=0; i<400000; i++) {
    a[i] = new Obj("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx");
  }

  d.innerHTML = "PAGE LOADED";
}

function cleanup() {
  for (var i=0; i<400000; i++) {
    a[i] = null;
  }
}

function Obj(msg) {
  this.msg=msg;
}

</script>
</head>
<body>
</body>
</html>

I shouldn’t need the cleanup() call on window.unload, but tried that also. No luck. As you can see this is simple JS, no circular DOM links, no closures. I monitor the memory usage using ‘top’ on Mac 10.4.11. Memory usage spikes up on page load, as expected. In FF and Safari reloading the page does not use any further memory, and all memory is returned when the window (tab) is closed. In Opera, memory spikes on load, and seems to also spike further on each reload (but not always…). But regardless of reload, memory never goes back down below the initial load spike.

I had hoped this was a no-brainer test that all browsers would pass, so I could move on to more “interesting” conditions. Am I doing something wrong here? Or is this a known Opera issue?

Thanks!
-joe


Update:
I accepted chris’ answer. The support link didn’t directly help, but it got me thinking (always a good thing).

Per the support docs I tried setting opera.setOverrideHistoryNavigationMode=’compatible’ in my JS, but it didn’t change anything. As I understand the docs, this method takes priority over any opera:config setting, etc.

But, I tend to agree that there’s some Opera optimization going on here. I’m not an Opera user, so am just getting familiar with all their config stuff for this test…

I turned off all memory caching in Opera user prefs for this test. This worked. Memory was reclaimed on closing the window. So it cannot be a leak.

One other thing I noticed:
In Firefox and Safari, and very possibly other browsers, if there’s no window.onunload handler then memory is only reclaimed when the window is closed. Memory is NOT reclaimed if the user navigates elsewhere. So if you load a huge page full of JS objects, then spend the rest of the day browsing plain HTML pages, you don’t get the memory back for a long time.

But, if you include a simple “do nothing” window.onunload handler, like:
window.onunload=dummy;
function dummy() {}
then memory is reclaimed even on navigation away from the page. From what little I’ve been able to read on the subject, this seems to be known, desired behavior.

Opera is different. Even with memory cache disabled, memory is only reclaimed on window close, not on unload-by-navigation. Go figure.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T03:29:59+00:00Added an answer on May 14, 2026 at 3:29 am

    I really don’t know, but maybe it’s related to this.
    http://www.opera.com/support/kb/view/827/

    Opera’s crazy fast back button must be doing something. I noticed it feels a bit different since they released 10.5(some pages feel slower…maybe they tuned it), so maybe that’s why some people here say they can’t reproduce the memory leak.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.