Great memory usage for dummies

I just restarted my Firefox browser because it started to stutter and slow down. This happens every other day due to (my understanding) excessive memory usage. I noticed that at startup it takes 40M, and then, by the time I notice that it is slowing down, it goes to 1G and my machine no longer offers if I don't close other applications. I am trying to understand the technical reasons why its such a difficult problem for sol ve.

Mozilla has a page on high memory usage:

http://support.mozilla.com/en-US/kb/High+memory+usage

But I am looking for a slightly deeper and more satisfactory explanation. Not super technical, but enough to give this issue more respect and please the crowd here.

Some questions I’m already considering (they might be dumb, so take it easy):

  • When I close all tabs, why doesn't memory usage go all the way down?
  • Why are there no restrictions on the use of memory extensions / themes / plugins?
  • Why does memory usage increase if it remains open for a long period of time?
  • Why is memory leak so hard to find and fix?

The agnostic responses of applications and language are also greatly appreciated.

+6
c ++ memory-management firefox memory-leaks
source share
4 answers

Browsers look like people - they become old, they swell, and they fall into a younger and slimmer model.

Firefox is not just a browser, it is an ecosystem. Although I think the latest versions are pretty bloated, the main product is generally stable.

However, firefox is an ecosystem / platform for:

1) Poorly written plugins

2) Poorly written JavaScript code that runs inside it.

3) Adobe flash as a platform for heavy video and for poorly written advertising scenarios, such as "hit Osama bin Laden with duck to reduce mortgage rates and get a free iPod * (participation required).

4) Quicktime and another media player.

5) Some built-in Java codes.

The memory leak description suggests that the script is running amok or a third-party tool requesting more memory. If you've ever run Flash on a Mac, it's almost the same as 90% of the processor load.

The goal of most programming languages ​​is not to save you, but to provide you with tools for salvation. You can write bad and bloated code with memory leaks in any language, including garbage collection. Third-party tools are usually not as well tested as the platform itself. Web pages that try to do too much are also not uncommon.

If you want to do an experiment to demonstrate this, get a mac from Firefox and go to a well-written site like Stack Overflow, and spend an hour. Memory usage should not increase much. Then spend 5 minutes on random pages on Myspace.

Now let me try to answer your questions based on my guesses, as I am not familiar with the source code

  • When I close all tabs, why doesn't memory use the way down?

While each browser instance is an independent process with its own memory, tabs in one window are in the same process. Some kind of in-memory caching was used in Firefox, and just closing the tab does not immediately remove the corresponding information from the in-memory cache. If you re-open a tab on the same site, you may get better performance. There was some advanced option allowing you to disable it, something like browser.cache.memory.enable. Or just do a search to disable the memory cache.

* Why is there no limits on extensions/themes/plugins memory usage? 

For the same reason that Windows or Linux does not have a process for checking applications that you can run on them. This is an open environment and you take the risk. If you need an environment in which apps and extensions are β€œtested”, Apple might be the way to go :)

 * Why does the memory usage increase if it left open for long periods of time? 

Not all calculations and actions in a script have visual manifestations. A script can do some things in the background (for example, request additional materials, preload things, just errors), even if you don't see them.

 * Why are memory leaks so difficult to find and fix? 

This is about accounting. Think about every item you've ever held (even a pen), or that someone has borrowed from you in your entire life. Are they all accounted for? Memory leaks are the same (you are taking up memory from the system), except that you are transferring objects around. Then look at the things on your desk, you left something lying because β€œyou may need it soon”, although you probably won't? the same story.

+10
source share
  • Why is memory leak so hard to find and fix?

Because some developers refuse to use tools like Electric Fence.

+2
source share

Memory leaks are present primarily because you want to store things in memory, not on disk. For example, suppose you have a webpage with images, CSS, JavaSript, text. If you go to your hard drive every time you want to use a JavaScript interpreter or CSS parser or a font display engine to display text, then the browser will be very slow and sometimes will not work (because one piece of JavaScript may need variables that , for example, left part of JavaScript). Therefore, the browser tries to save everything necessary for working in memory, and these things are easily cross-referenced (calling JavaScript in Adobe Flash, calling Adobe Flash in JavaScript, etc.). And you should be very careful with such links to resources, because cleaning them prematurely and out of order will violate the code (it is better to save the resource and then die suddenly because it does not exist).

PS See also this article for some details.

+1
source share

Wikipedia has a God article on memory leaks: http://en.wikipedia.org/wiki/Memory_leak

0
source share

All Articles