Catch up on stories from the past week (and beyond) at the Slashdot story archive

 



Forgot your password?
typodupeerror
×

Firefox Memory Leak is a Feature 602

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."
This discussion has been archived. No new comments can be posted.

Firefox Memory Leak is a Feature

Comments Filter:
  • Christ is it a waste (Score:1, Interesting)

    by heinousjay ( 683506 ) on Tuesday February 14, 2006 @06:46PM (#14720112) Journal
    I left Firefox running overnight by accident, and when I woke up, the working set was over 2 gigs. I think that might be a touch excessive.

    I still like it as a browser, though.
  • My pet peeve! (Score:2, Interesting)

    by RingDev ( 879105 ) on Tuesday February 14, 2006 @06:47PM (#14720116) Homepage Journal
    "(studies show that 39% of all page navigations are renavigations to pages visited less than 10 pages ago, usually using the back button)"

    So why is it that when I open a new tab I have to manually cut/paste the same address in it. For example, replying to an article on /., If I want to quote the summary, I need to hit the back button to copy the text I want, then forward again to paste and type. Why can't I hit ctrl-T and get a new tab with the same page I'm currently on, then hit reply and anything I want to quote I can just switch tabs instead of screwing around with back/forward and scrolling.

    -Rick
  • Re:My pet peeve! (Score:3, Interesting)

    by pete6677 ( 681676 ) on Tuesday February 14, 2006 @06:55PM (#14720197)
    That would be a nice user-configurable option. As it is, I don't find it too much trouble to hit shift-tab a couple of times, ctrl-C, ctrl-T, ctrl-V, enter to get the same page in a new tab, but it would save a few steps to have this choice. But I definitely wouldn't want new tabs opening up with the current page and no option to turn this feature off.
  • releasing memory (Score:5, Interesting)

    by DreadSpoon ( 653424 ) on Tuesday February 14, 2006 @07:25PM (#14720433) Journal
    The answer to that is pretty simple:

    The heap, where dynamic allocations occur, is only allowed to grow or to be truncated. An application cannot release memory in the middle of the heap without also releasing the memory at the end of the heap.

    So let's say Firefox makes 10 one-page allocations, and frees the first 9. The memory layout might look something like:
    XXXXXXXXXU (X- unused, U- used)

    Those 9 pages worth of memory aren't being used, but it's impossible to release them back to the OS.

    Thankfully, there is some good news: when Firefox needs to allocate more memory, it can and will just reuse those 9 unused pages instead of allocating more memory from the OS and growing the heap.

    The best solution to this problem is to use a compacting garbage collector. Which is something that Java and C# and other higher-level langauges can easily make use of (and many do use them), but which C and C++ can't really make use of given the complete lack of compiler support. That's one reason why a Java or C# app can actually out-perform a similar C/C++ app, especially with a good native-code compiler and an library implementation with a modern GC.
  • Don't bug me (Score:5, Interesting)

    by joeytsai ( 49613 ) on Tuesday February 14, 2006 @07:31PM (#14720478) Homepage
    I think this submission is confusing two points. First of all, is this really a memory leak? A program that uses a lot of memory is not necessarily a leaking program. A memory leak is a programmatic error where memory is allocated but never freed, even when there's no way to use that object again. As the program continues to allocate memory, the heap size of the process increases until eventually the OS terminates the process (eg., the OOMKiller). Actually, many applications you normally use leak memory - but as long as they don't waste a ridiculous amount of memory most people don't care, especially since most process lifetimes are relatively short (compared to a daemon process like apache), and after termination the OS reclaims all the program's memory, leaked or not.

    What is being described here sounds much more like a cache of recent pages, which in my opinion is perfectly sane for a browser. Sure, maybe the cache is a bit overzealous, but even if that's the case, just disable it - worse case scenario, you edit the source. But otherwise, this is definitely a feature - I can promise you it's much more programming effort to save old pages for a quick redraw than to free the old page and replace it with the new.

    So I guess the discussion here is, "is it right for firefox to use so much memory?" My answer is yes. It is not a memory leak, it seems like a very valid design decision. But if you disagree, old versions of firefox still work great (I still haven't upgraded myself).
  • by JordanL ( 886154 ) <jordan,ledoux&gmail,com> on Tuesday February 14, 2006 @07:54PM (#14720674) Homepage
    I suspect that some of it may be due to talent. Perhaps Opera programmers are just more talented on average than the typical FF dev. As well, I also suspect that its simple goal orientation. The Opera company works on building a new browser that's better with new features. The MozDevs collaborate on whose got which tickets and how they'll be integrated into the source and such.

    This is proof positive, I think, that OSS != the best option in all scenarios. Opera consistently beats FF out on features, security, and speed... and it does it without having to download "extensions".
  • Re:releasing memory (Score:3, Interesting)

    by mrsbrisby ( 60242 ) on Tuesday February 14, 2006 @08:16PM (#14720846) Homepage
    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.

    mmap() can do this, but on many systems [s]brk() cannot. brk() is also alot faster than mmap().

    This is really moot on most systems; don't do a lot of little allocations that you're going to keep around for a while and DO use pooled allocators that can use mmap(). It requires planning, but it really does pay off for applications that need an awful lot of memory in stages.

    This is (by the way), why many C compilers are implemented in "stages", so that they don't have to worry about crap like this. Allocate as needed, and the next stage exec() will automatically compact and garbage collect any pages used in the previous stage that aren't needed here (that weren't passed to the next process using mmap or pipes).
  • by tepples ( 727027 ) <tepples.gmail@com> on Tuesday February 14, 2006 @08:32PM (#14720955) Homepage Journal

    memory is released upon calling free()

    Too many C libraries' implementation of free() release memory back to the application, not to the operating system.

  • by Mini-Geek ( 915324 ) on Tuesday February 14, 2006 @08:40PM (#14720999) Homepage
    The person that sent in this article is mistaken. In Firefox 1.0 the Memory Leak still existed without caching previous pages completely as is currently done. Do I need to say anything else? It may be possible that the new caching system worsens the problem slightly, but it's not the cause of it.
  • by Michalson ( 638911 ) on Tuesday February 14, 2006 @08:50PM (#14721056)
    Thank you thank you thank you (sorry ot no mod points, but you're already up to 5 anyway).

    I browse with a lot of tabs in FireFox, and with FireFox 1.5 the performance when a lot of those tabs are loading has been beyond horrible. Like several seconds just to switch tabs, and then actually trying to scroll...

    If you are feeling generous, perhaps you also know how to shutoff the new tab thumbnail "feature" when you've got images. 16x16 thumbnails of 4000x4000 images are nothing but a waste of CPU time and a visual distraction.
  • by crabpeople ( 720852 ) on Tuesday February 14, 2006 @08:53PM (#14721071) Journal
    firefox currently sitting at 0% cpu usage. perhaps you should upgrade your pentium 133 :)\

    seriously, the only thing i could think of is that if firefox ran out of ram and had to start using the pagefile, that would eat up tonnes of CPU. This would also effect other programs on the system. Are you sure you have enough ram in the machine? I assume you can replicate this bug on more than one machine right?

    Ive had some sites crash firefox repeatidly but i cant think of any examples off hand.

  • Re:sounds good to me (Score:3, Interesting)

    by jlarocco ( 851450 ) on Tuesday February 14, 2006 @09:12PM (#14721162) Homepage
    Why is everyone bitching about this? I hate waiting for any refetch or rerendering when I use the Back button; I want it to be instantaneous. That page was fetched and rendered aslready, so having the browser keep it around for when I go back to it is exactly what I'd want it to do.

    You've totally missed the point. People aren't bitching because the back and forward buttons are faster. They're bitching because the memory used for the fast back/forward is never released. Because Opera implements the same feature even faster and doesn't use >85% of physical memory after 20 minutes. Because a web browser should not use >1 GB of RAM because it's left open over night.

  • I am using:
    Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7.12)

    And I can not duplicate any of those issues.
    When clicking forwadr and back buttons quickyl, I manged to spike at 60% for a brief moment.
    I have ahd it running all day.
    I do not use the feature that lets some of it stay resident so opening it up is quicker, so maybe the problem is there.
    Any clues on ther things I can try to duplicate this issue?

    to address this specific issue, more memory does not equal memory leak. Yes, the cahching mechanizim may be too agressive, but if it ahs been designed that way, then it is, in fact, a feature.
    Some other poster suggest setting changes that seem to take care of this issue.
  • by masklinn ( 823351 ) <.slashdot.org. .at. .masklinn.net.> on Tuesday February 14, 2006 @09:29PM (#14721256)
    Sorry? When I'm using Opera I often see it ramping above 150Mb of ram usage, that's equivalent to Firefox' RAM consumption on my machine.
  • Simple fix (Score:2, Interesting)

    by Cryolithic ( 563545 ) on Tuesday February 14, 2006 @09:30PM (#14721260)
    Go to about:config Create a new boolean name it config.trim_on_minimize set it to true Next time firefox is using too much ram, quickly minimize it, then bring it back up. Done.
  • by diegocgteleline.es ( 653730 ) on Tuesday February 14, 2006 @10:08PM (#14721486)
    and it does it without having to download "extensions"

    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.
  • Re:Don't bug me (Score:1, Interesting)

    by Anonymous Coward on Tuesday February 14, 2006 @10:43PM (#14721683)
    FWIW, I tried disabling said feature months ago with virtually no difference in memory usage (and no extensions installed).

    Firefox 1.5 was regularly using 1GB+ of memory under normal browsing with _one_ tab. I have 1gb of actual memory so it was spilling over into the page file on the hd and affecting all other programs. Personally I've never seen such an obscene memory leak on non beta software, even from IE. However, now that I'm using 1.5.0.1, I haven't seen it go over 200mb of memory usage. Clearly there was a major problem somewhere that was fixed.
  • Cluecheck! (Score:3, Interesting)

    by Burz ( 138833 ) on Tuesday February 14, 2006 @10:44PM (#14721685) Homepage Journal
    I just loaded FF 1.5.0.1 and Opera 8.5 on Mac OSX 10.3.9 (iBook G4 1.2GHz 768M) each with identical nine tabs:

    Firefox: 54.15M (Real) 190.07M (VM) ; 2.1% idle

    Opera : 59.36M (Real) 239.66M (VM) ; 0.4% idle

    Assessment: This Firefox outperforms both Opera and Safari in memory usage, and is faster than Opera on challenging pages. However it has the least favorable idling habits, starting at 2% here and would climb to 4% after several days of intensive use. FF 1.5.0.1 memory use would climb to about 100M for the same pages over the same period, indicating the cache grows somewhat but not wildly the way FF 1.5 did.

    The test of also rather unfair, as I have 7 FF extensions running.
  • by Edgewize ( 262271 ) on Tuesday February 14, 2006 @11:41PM (#14721940)
    You're confusing garbage collection with heap compaction.

    People have written garbage collectors for C++, and they work just fine. But they do not help with fragmentation, which is the problem you're describing. That requires a heap-compacting allocator (aka a "handle" allocator). Many languages with garbage collection also use a heap-compacting allocator. C++ does not, because of a low-level language "feature": pointers, and specifically, pointer arithmetic.

    If an object moves in memory, then people have to be notified that it has moved, or they won't know where to access it. Languages like Java handle this behind-the-scenes; the system library tracks objects for you, and your program never knows (or cares) whre an individual object is.

    C++ allows direct access to system memory, and it tells you precisely where your objects are located. Programmers are then free to do all kinds of things like compute distance to other objects, or convert the location to a number and do arbitrary math operations on it.

    When an object moves, anything that refers to it needs to be updated. Well, good luck figuring that out in a language with pointer arithmetic! The system would need to magically determine whether or not a numeric value was actually a memory locations. And what if a program computed the distance between two objects, and later on used that distance to get from one object to the other? The system has no idea of what can be safely moved, and what has to stay put. So nothing can ever be moved.

    There are workarounds of course -- if you write a program with heap-compaction in mind, then you can use a "handle" system, where every object has an ID. You remember the ID, and to access the object, you ask the system for a temporary memory location. And as soon as you're done, you "forget" the memory location and let the system shuffle things around in memory. The next time you give that ID to the system, you might get back a different memory location, but you were already expecting that so your program doesn't mind.

    But handle allocation is slower, less efficient, and more annoying to use than a traditional fixed-location allocator. You have to start your project with it in mind; retrofitting existing code to use a handle allocator is a giant timesink and prone to conversion errors. And if you don't mind the loss of performance due to using a handle allocator, why are you using C++ in the first place?
  • POST data? (Score:3, Interesting)

    by Quixote ( 154172 ) * on Tuesday February 14, 2006 @11:46PM (#14721972) Homepage Journal
    If Firefox is caching these pages, why doesn't it cache POST results? When I hit back to go back to a page obtained via POST, FF refuses to show it to me, asking me to either cancel the action or resubmit the form. JUST SHOW ME THE GODDAMMN PAGE, DAMMIT!. Once the page lands in my machine, regardless of how I obtained it (i.e. via GET, POST or whatever), then just show it, or at the very least give me the option of seeing the possibly expired page. Let it be my decision.
  • by Siguy ( 634325 ) on Wednesday February 15, 2006 @02:05AM (#14722482)
    How does this explain why firefox eats more and more and more memory when left alone.

    If I leave my computer on and come back the next morning, with no new pages having been loaded, the browser is suddenly taking up like 400 megs of RAM.

    That can't be explained by caching tabs.
  • by Tony Hoyle ( 11698 ) <tmh@nodomain.org> on Wednesday February 15, 2006 @02:21AM (#14722533) Homepage
    You use double-pointers rather than handles. No need to notify anyone.

    I used to use this years ago on machines like the archimedes that had little memory. In a modern paged system it's a nearly useless technique - the most you'll lose is a single page even if there are large 'gaps' in the virtual address space.
  • by cruachan ( 113813 ) on Wednesday February 15, 2006 @03:56AM (#14722801)
    Give up and use Opera. Firefox is profoundly broken in combination with (a) memory leak being discussed and (b) memory leaks in plugins. The second seems to even include Flash, where some flash pages appear to be cache in active state and sit there using CPU cycles as well as memory.

    I think we've no got to the state where Firefox can be seen as a nice try, but no cigar. Opera on the other hand just works - and increadibly it's quick and lean too.

    I've no connection with Opera, just like many I've been through the "Dump IE, Use Firefox, Think Firefox is wonderful, Find Firefox's dreadful memory/cpu cycle leaks, Dump Firefox" cycle!
  • by Arimus ( 198136 ) on Wednesday February 15, 2006 @04:37AM (#14722921)
    First off I like Firefox and its my primary browser of choice. HOWEVER this calling a bug a feature doesn't half remind me of a certain other company I could mention (and several Dilbert cartoons).

    If this feature is for my benifit then let me decide whether to use it or not. Apart from that it does not explain why when I leave firefox idle with only one window open on a simple HTML page over time my memory useage goes up...

    Stop hiding behind feable excuses and actually work on reducing the footprint firefox uses... FF is suposed to be a lightweight browser alternative to the usual browser bloatware - it is failing at the moment (rather like my spelling ;) ).
  • by Anonymous Coward on Wednesday February 15, 2006 @04:37AM (#14722924)
    Programmers are then free to do all kinds of things like compute distance to other objects, or convert the location to a number and do arbitrary math operations on it.

    Actually, neither of these things are guaranteed to work by the C++ standard. Implementations usually make it work, because it's more easy than not and occasionally convenient.

    I think you could do a heap-compacting implementation of C++. Unlike conservative garbage collection, however, you can't do it in a library. Pointers would double in size and become handle-offset pairs, plus an entry in a map for each heap block. Every pointer access would also take a second indirection. As a side benefit, this makes garbage collection and bounds checking a little easier.

    Things like taking the difference of pointers to two objects not in the same array would not work, but C++ doesn't guarantee it anyway. Converting pointers to ints and back wouldn't either, but same deal.

    But the problem is, someone needs to implement it. And that someone needs to also have a compiler that they can modify in terrible, terrible ways. It also would help to be an expert in designing thread-safe, interruptable heap compaction algorithms.

    Now, if you were in a position to do that, would you bolt this on to C++, or would you put that effort into a different language?
  • by Anonymous Coward on Wednesday February 15, 2006 @05:01AM (#14722985)
    The point you describe is very misleading. While you are technically correct, it is of no relevance. You need to differentiate between virtual address space and actual used memory. Just because you have pointers pointing to addresses 1 and 4 billion ( hex numbers omitted on purpose ) that does not mean you are using all the memory in between. In this particular case, you are probably only using 2 memory pages which will likely consume only a few bytes. Therefore, the effect you describe is a) not connected to C++ and b) is not the problem with firefox. Opera for example is written in C++ and memory-usage, even with 100+ open tabs with lots of graphics is lower than any other browser i know.
  • by klui ( 457783 ) on Wednesday February 15, 2006 @05:33AM (#14723049)
    I find that if I set browser.sessionhistory.max_total_viewers to 2 it uses less memory if it's left at the default (I have 1GB RAM). If I use Fasterfox's Clear Cache function, it compacts the memory usage even more. There is still some leakage but not as bad as the default -1.
  • by OneSmartFellow ( 716217 ) on Wednesday February 15, 2006 @05:37AM (#14723060)
    I find firefox to be one of the worst browsers - for my use anyway - available. I have tried to use it over an X session, and basically gave up; and that was with my X client running on a P4 1.5 GHz 500M RAM linux server, and my X server (running on my client machine accessing the server) a similar spec machine. The connection was wired 100MB ethernet.

    Considering the hooplah that goes along with it, firefox underperforms on basic tasks when compared to KDE's Konqueror.

    What's worse is that this command firefox ./index.html tries to open http://index.html/ rather than file://index.html. Meanwhile Konqueror behaves correctly.

  • Competition (Score:3, Interesting)

    by Britz ( 170620 ) on Wednesday February 15, 2006 @05:43AM (#14723073)
    First everyone complains that they should be as fast as possible to compete with IE, which is pretty fast.

    When they do it the get slapped for using too much resources?

    But I see a good point. I also would like to see new developement halted for some time to catch bugs and security problems. This would also help plugin developers to catch up. New features could be developed in plugins anyways.
  • by luckystuff ( 836232 ) on Wednesday February 15, 2006 @11:34AM (#14724548)
    wow. first time in a long while I have read something /.'d and put it to *immediate* use. congrats.

Any circuit design must contain at least one part which is obsolete, two parts which are unobtainable, and three parts which are still under development.

Working...