Slashdot Mirror


Firefox Memory Leak is a Feature

SenseOfHumor writes "The Firefox memory leak is not a bug. It's a feature! The 'feature' is how the pages are cached in a tabbed environment." From the article: "To improve performance when navigating (studies show that 39% of all page navigations are renavigations to pages visited less than 10 pages ago, usually using the back button), Firefox 1.5 implements a Back-Forward cache that retains the rendered document for the last five session history entries for each tab. This is a lot of data. If you have a lot of tabs, Firefox's memory usage can climb dramatically. It's a trade-off. What you get out of it is faster performance as you navigate the web."

25 of 602 comments (clear)

  1. Total cached page limit. by Short+Circuit · · Score: 5, Insightful

    So there's a way to limit the number of cached pages per tab, but no way to limit the total number of cached pages, for those of us who have fifteen tabs open?

    Whoops!

    1. Re:Total cached page limit. by Rolan · · Score: 4, Insightful

      Yeah, where can I turn off this "feature"? Or, better yet, why doesn't this "feature" release memory when the tab is closed? Either of those would make me much much happier with Firefox.

      --
      - AMW
    2. Re:Total cached page limit. by Short+Circuit · · Score: 2, Insightful

      I wouldn't call completely disabling the feature an optimal solution.

      Me, I'd like to limit it to 25 cached pages, and have the old ones shuffled out as new ones are shuffled in.

    3. Re:Total cached page limit. by Mistshadow2k4 · · Score: 2, Insightful

      Thank you. My machine has 512 mb RAM (planning ot upgrade soon) and I multi-task a lot, so when I'm running FF I'm almost running 1 or 2 other programs at the same time. That's why it's very high use of memory becomes a problem. And with a fast connection like I have now, I can't tell that my page load performance is suffering at all.

      But... what they should do is to put this in the regular optios menu instead of about:config. Lots of users don't even know to use about:config. I really like FF but the "we know better than you" attitude of the Moz team is starting to bug me. No, it's my machine and I know what I want to do with it, so I think I just might know better than they do.

      --
      I dream of a better world... one in which chickens can cross roads without their motives being questioned.
  2. spyware with IE or memory leak with FF.. by madnuke · · Score: 2, Insightful

    Hard choice but I'm seriously looking at Opera after seeing this I have a gig of RAM and its still laggy, I was wondering why the 'leak' was so high theres no way you could put that much bad programing to make a programe eat memory like a fat kid in a pie shop.

  3. Doesn't seem to be true by amliebsch · · Score: 3, Insightful

    If this is true, then why is so little memory freed after the tab is closed, compared with how much it consumed when it was created?

    --
    If you don't know where you are going, you will wind up somewhere else.
  4. about:config by __aaitqo8496 · · Score: 2, Insightful

    how about a configurable option to not take up 200mb of ram? keep it as-is by default, but let power users toggle it off

  5. So I'll be the first to say it.... by JordanL · · Score: 4, Insightful

    Why does Opera do the same thing faster without the memory penalties?

    1. Re:So I'll be the first to say it.... by JordanL · · Score: 1, Insightful

      Well, you just picked up the worst reason - opera is great when it comes to performance, but firefox + extensions consistently beat opera and IE when it comes to features. I can have the features I want, there're way more extensions that features than opera has, and if I don't want them, I don't need to keep the extra UI involved in those features.

      You sound like you've never actually picked up Opera and used it...

      Unlike FireFox, Opera's features don't ever seem to add bulk to the interface. I'm continually impressed with the elegance of the UI. The downside on that one is that configuring these features isn't as slap-you-in-the-face obvious as it is in FireFox, although just as powerful.

      Opera has a 'feature' just like Thunderbird integrated that I never use... and if I didn't read the development logs, I wouldn't even know it existed.

      I've never found a FF extension which added a genuinely useful feature that wasn't already in Opera, with the exception of GreaseMonkey, (which enjoys full support in the upcoming 9.0 release).

  6. What I'd like Mozilla devs to do by A+beautiful+mind · · Score: 5, Insightful
    Let them release 2.0, but then try to focus on:
    • fixing the practically fixable bugs (not the design decisions)
    • making code performance improvements (faster, with less memory!)
    • security auditing
    ...for a half year or a year. I don't need new features, I'm currently happy with the ones I have and I'd prefer the current features working securely, in a speedy fashion and mostly without bugs. This time period would also give enough time for extensions to mature more.

    Before someone jumps at my throat, it's just a description what I'd like to see, but of course its all up to the developers, they decide what to code and do with their time. It is just simple user feedback.
    --
    It takes a man to suffer ignorance and smile
    Be yourself no matter what they say
  7. Huh? by countach · · Score: 4, Insightful

    Uh, using a lot of memory is not the same as a memory leak.

  8. Re:Wow. If this excuse had come from MS... by Anonymous Coward · · Score: 0, Insightful

    Uhuh. It's the same with Google.

    One minute we're all pro-civil liberties, pro-free speech, anti-censorship, anti-repression but the moment Google wants to do business in China, 'they're only following the laws of that country', they're doing nothing wrong. Switch with Microsoft and they'd be 'dealing with an evil regime, shame on them' yadda yadda.

    Same with Nintendo. Bash Microsoft and Sony for coming out with unoriginal sequels yet Nintendo are such innovators for bringing out Metroid Fusion, Super Smash Brothers Melee and Super Mario Rainbow Warrior.

  9. Re:releasing memory by Anonymous Coward · · Score: 2, Insightful

    An application cannot release memory in the middle of the heap without also releasing the memory at the end of the heap.

    That's not strictly true. If the hole is larger than 4k (or 8 if it's not page-aligned), there are two things that can be done.

    You can decommit the page, but keep it reserved. This frees RAM, decreasing the process's memory usage, but still takes up some of its address space. You MUST coalesce free heap blocks in this case, because all data in those pages is lost. This also requires extra housekeeping.

    Or you can keep it committed, and the OS will push that memory out to the page file. This is done pretty much automatically, but it's more lazy. In Windows, you can somewhat force this by minimizing all windows owned by the process.

    The best solution to this problem is to use a compacting garbage collector.

    Unless you've done actual research, I wouldn't be so quick to say that. It's certainly the easiest solution if you're using a language that doesn't use real pointers, but there are numerous possible solutions.

    Eg, you could allocate pages for large objects like this directly from the OS rather than using a heap. Then freeing objects in the middle is no problem at all.

  10. Re:releasing memory by Bloater · · Score: 4, Insightful

    > Wouldn't all pointer references then have to go through some kind of lookup table, so that the objects could be relocated by the runtime without breaking them?

    Only on a computer without virtual memory. In a PC (which *has* virtual memory), you just punch holes in the memory.

    What happens is a process gets an "address space", into which pointers can point, but any given address may not map onto some real storage. The process asks the operating system to map a range of addresses onto real storage which the operating system will try to map to real fast memory when it thinks it will be used at any moment. When the OS figures the memory wont be needed for a while, and something else needs some memory, the OS copies the data to disk and redirects the mapping to a proxy that will pull the data back into memory when the process tries to use it again.

    When a process knows that it won't need a section of that real storage, it can tell the operating system to unmap it from the address space.

    There are various other things that go on, but that's the simple story. From a figure posted in an earlier message, it seems that opera does pretty damned well (in comparison to most modern programs) with just the simple story, not having to rely much on nasty unreliable heuristics. Of that I am impressed.

  11. Re:releasing memory by Klootzak · · Score: 3, Insightful

    Excellent post, well worth the +5.

    But you pointed out the flaw in the wording of the article - this IS NOT a memory leak, just inefficient use of the heap.

    I thought the definition of a memory leak was an application that kept allocating memory from the OS as it ran, not an application that asked for a chunk of memory and just reused it inefficiently?
    (If I'm wrong, someone please correct me).

    --
    A Man's ethical behavior should be based effectually on sympathy, education, and social ties -- Albert Einstein
  12. Firefox developers don't "get it" by Vellmont · · Score: 5, Insightful

    Memory isn't an unlimited resource you just hoard whenever you think you need it. Right now my instance of firefox is taking up 128 megs! I've seen it up to 256 megs before. This is just simply insane. I've seen people who's computer performance has gone down the tubes because firefox is taking up all the memory (and these are machines with 512 megs of memory, not exactly tiny). What I'd like to convey to the firefox devs is this: Your application isn't the only one running on the system. Play nice and don't be a hog.

    With the number of people complaining about this (and the number of people that don't even KNOW to complain) isn't it a safe bet that you've made a mistake in the amount of cached pages?

    --
    AccountKiller
    1. Re:Firefox developers don't "get it" by Nimey · · Score: 3, Insightful

      You could always close the browser when you're not using it. I close any non-daemon I'm not using, and it makes my system more responsive.

      --
      Hail Eris, full of mischief...

      E pluribus sanguinem
  13. Doesn't this just seem silly? by robertjw · · Score: 2, Insightful

    The cache feature is nice, but why distribute it out to every tab? If I have 20 tabs open I'm not going to be constantly clicking the back button on each of them. Why not clear the cache on tabs that haven't been accessed recently and only keep cache on tabs actively being used. Often when I open new tabs I just want to be able to quickly access that page, or use it as a temporary bookmark - not navigate back through the path that got me there.

  14. Re:bfd? by Sigma+7 · · Score: 4, Insightful
    Virtual memory, look into it!


    Virtual memory is not a carte blanche for memory hogging. As you should know, memory hogging will result in degraded performance.

    Assuming that users have unlimited resources is exactly how Mozilla is barely usable on Windows 95-ME - especially when you have Slashdot Moderator access.

    Who cares if Firefox or any app is a bit of a memory hog???

    As long as it is just using the memory as cache space and not accessing the memory randomly, it'll be paged out into virtual memory as needed.


    In an ideal situation, that would be correct.

    However, the operating system does not know which memory is currenly "in use" and which ones are "in cache" - in fact, it's quite easy for an "in use" to be physically sandwiched between two "in cache" entries. Because of this, you will have a sudden loading time if you do plenty of other tasks in the background and suddenly switch back to Mozilla.

    Small applications, being small, do not generally have to wait 1/2 seconds to recover from being pages in or out. Since Mozilla allocates the cache in memory, it will have to wait those two seconds.

    assuming you're using an OS with decent vmem support.


    An OS with decent vmem support would allow you to map files to memory. This results in no swapping at all - only writing perodic output to the hard drive, and loading the file into memory as required. If another application needs more memory, the memory map is discarded with no need to write the contents of memory.

    An application that doesn't exploit the usage of memory maps is as good as an OS with shoddy vmem support. (Of course, it can simply use it's disk cache for the same effect.)

  15. Re:Obviously there is a memory penalty with Opera by dreemernj · · Score: 2, Insightful

    Opera uses disk cache and ram cache. It uses as much ram cache as it can for the speed benefit, and on older systems with less memory it tones down the ram cache usage to avoid stepping on toes. In any case how much disk and ram cache it uses can both be controlled manually from the preferences. Ram is set to auto by default meaning it will take a percentage of the free memory for itself. On my 1gb system it tends to use about 90-120megs of ram if I've been browsing for a while, but it does keep a cap even on that system so it never gets so large that it gets bogged down. Then on systems like the one I am on right now that has 128mb ram, it relies mostly on disk cache and doesn't really suffer any hits in performance for it.

    --
    1 (short ton / firkin) = 89.1432354 slugs / keg
  16. Re:Your usage pattern is different. by Anonymous Coward · · Score: 1, Insightful

    Welcome to the real world. If QA cannot duplicate a bug, then the chance that it'll be taken seriously is low, let alone being fixed. They don't have all day for one bug that's not reproducible by them.

  17. I'm definitely insane by try_anything · · Score: 2, Insightful

    Every time I close all the tabs in my browser session except two or three, then check a few hours later and see that Firefox is sluggish and hogging a few hundred megabytes, I go to the police and ask them to take me into protective custody. I'm obviously a danger to myself and others. When I'm not responsible enough to seek psychiatric help, I just stare at my monitor and tell myself, "You only see three tabs there, but that's because you're crazy. You still have all those dozens of porn tabs open. You just can't see them because you went blind masturbating."

    Seriously, what's with all the song and dance? Firefox obviously has at least one problem, probably several, that leads to bad performance for many users, under certain circumstances. Call it a UI problem, call it a documentation problem, I don't care, just call it a problem. Don't call it a feature or a misunderstanding. Don't pick a feature that can't account for many of the reported problems and say, "Aha! This is THE Firefox memory leak that's bothering everyone. See? It's a feature!" The denials and talk-arounds on this issue are what you would expect from a political party, not an open-source software project.

    Of course, I only know all this because I use Firefox. It's the best. The memory problems would only be a minor annoyance if I didn't have to constantly read about how I'm crazy or stupid.

  18. Per Session, not per Tab by dzfoo · · Score: 2, Insightful

    Its a non-issue. As explained on a note at the end of the article, its a per session setting, not per tab, so the entire article misrepresented the "feature".

    "Edit: In the comments, Boris and David pointed out that I misread the code, and that this is a global preference so that there are no more than 8 cached pages for the entire session, not per tab. My initial posting had claimed that it was per-tab. Oops!"

    If Firefox has memory leaks (and I think it does), this is not what is causing it. If it were, however, per tab, as the article originally claimed, then it would have been a problem, because the more tabs you open, the memory usage increases at an alarming rate, if it has to keep up to 8 history pages cached.

    Nothing to see here. Move along.

              -dZ.

    --
    Carol vs. Ghost
    ...Can you save Christmas?
  19. Re:releasing memory by julesh · · Score: 2, Insightful

    The good news is that a false positive isn't going to cause direct harm in mark and sweep. All that happens is that space that could be used isn't

    Or an allocated page leaks. While the collector's "blacklisting" approach minimises the amount of this that happens, it does still happen from time to time.

    Boehm claims this is irrelevant in today's operating systems with virtual memory, although I doubt you'd see an entire page's worth of false positives.

    I'm not entirely sure I agree with him. Consider, for example, applications that store large arrays of seemingly random data on the stack (e.g. compressed data). As the amount of this data tends towards (2^32/PAGESIZE)*4 bytes (= 2^24 bytes, or 16Mb), the number of pages blacklisted should approach half of available virtual memory, reducing to 2Gb the memory available for the application on a 32 bit address system (i.e. todays standard). 2Gb is a lot, but many applications are starting to get close to that. And doubling the amount of randomised data on the stack will halve it, I think.

    Boehm does most of his work on 64 bit platforms these days. I'm not surprised that he's unconcerned about virtual address space usage.

    That said, it's very simple to avoid this pitfall: use GC_MALLOC_ATOMIC to allocate any space that will store apparently-random data. You just have to understand how the garbage collector works, and code around it, to avoid such problems. I guess we're looking at a leaky abstraction here, as always.

  20. Re:Why does Opera work well, and not Firefox? by Anonymous Coward · · Score: 1, Insightful

    If your CPU/Memory problems persist in Outlook, et. al., then I posit the problem is NOT Firefox, but instead an OS library gone awry. Why? Those other programs use IE whether you like it or not. If it affects IE, then it is a library used by both Firefox and IE.