Memory leaks and web browsers

This is an archive of a topic from NESdev BBS, taken in mid-October 2019 before a server upgrade.
View original topic
Memory leaks and web browsers
by on (#117622)
I had some memory leaks problems with Opera, and after doing some researsh on the net, I figured that all the major browsers appear to leak memory as soon as a page is open.

Isn't it incredible how much memory it can take just to open a web page (usually 400 MB) and consideing that if you don't close your browser after an extended period of time it's going to eat >1GB of memory, just because the coders of those programs didn't know how to use malloc and free properly ?
Re: Memory leaks and web browsers
by on (#117623)
Dunning–Kruger effect
Re: Memory leaks and web browsers
by on (#117624)
So basically you're saying I'm incompetent when it comes to using malloc and free ? Yes you are probably right, and I'd never get the competence of writing a web browser, so it's very easy for me to do blind criticism.

However, I still think it sucks that browsers tend to leak memory so much. But at least knowing the problem is good enough, I could explain a colleague why a PC he left on with both Firefox and Chrome running for a whole week ended up having some serious lagging problems at resume (with 100% of memory used and disc caching enabled etc etc...)
Re: Memory leaks and web browsers
by on (#117625)
Is caching page assets a memory leak? Also, Reducing [Firefox] memory usage.

If blame is to be laid, I lay it squarely on website designers who bloat these things beyond recognition, slowing down multi-hundred-MHz smartphone web browsers. That is what requires such sophisticated web browsers that implementations are complex enough to leave unsolved memory leaks and need lots of caching and other memory-intensive approaches to running at an acceptable speed.
Re: Memory leaks and web browsers
by on (#117626)
Quote:
Is caching page assets a memory leak?

No.
But then the cache shouldn't take 1GB or RAM either I think. This means more than 1 CD-ROM of cached data ? Makes few sense to me.

And I agree that bloated websites are quite annoying, even though I never access internet from a phone.
Re: Memory leaks and web browsers
by on (#117629)
It's not necessarily entirely the fault of the browser implementation. JavaScript running on an interval can periodically add things to an array, add listeners to a DOM element, etc. Should a browser just force-close a page whose script uses too much memory?
Re: Memory leaks and web browsers
by on (#117632)
Opera does not seem go beyond the limit if you set one. I keep a 400MByte memory cache and I don't see memory use grow beyond that even after days of use. Firefox eats up all the memory I have pretty quick...
Re: Memory leaks and web browsers
by on (#117658)
Does Opera have something equivalent to about:memory like in Firefox? If you use FF, close all instances (i.e. exit the browser entirely), launch it, and go to about:cache and about:memory (and click Measure) sometime. Prepare to be incredibly pissed off.

This is just how a lot of software is today -- "our" days of KISS and minimal resource usage are pretty much over; we're a dying breed of peoples. The "web" today often consists of so much unnecessary bullshit.
Re: Memory leaks and web browsers
by on (#117660)
That's why I have tried my best to design web applications with as little unnecessary BS as possible. How would you rate the bloat level in, say, Phil's Hobby Shop?
Re: Memory leaks and web browsers
by on (#117661)
tepples wrote:
That's why I have tried my best to design web applications with as little unnecessary BS as possible. How would you rate the bloat level in, say, Phil's Hobby Shop?

IT'S OVER NINE THOUSAND
Re: Memory leaks and web browsers
by on (#117662)
How do you not understand, if RAM is open, the web browser will compile javascript (well, chome will) an show it all to RAM to gain speed? I know this has come up.

And Chrome doesn't leak much memory to me. Firefox will destroy any computer left open for 2-3 days though. Opera, never used long enough to see how it's backsides were made. And IE probably doesn't leak much I'd bet, you have to be fixing something when you don't care about standards. :)If your
Re: Memory leaks and web browsers
by on (#117668)
3gengames wrote:
Firefox will destroy any computer left open for 2-3 days though.


? I regularly have Firefox open continuously for days. I'm not sure why you think this. At various times, various builds of each of the major browsers have had serious flaws, often manifesting for only a small subset of users, perhaps you had a bad experience with Firefox at some point, but it will hardly "destroy any computer". I've had builds of Chrome, Firefox, and Opera that failed to run well for me at the time, but in general I think all three of them are kept in good working order most of the time (not sure about Opera these days, haven't used it regularly in the last few years).

koitsu wrote:
This is just how a lot of software is today -- "our" days of KISS and minimal resource usage are pretty much over; we're a dying breed of peoples. The "web" today often consists of so much unnecessary bullshit.


There was never a day of minimal resource usage. Webpages are generally designed without concern for the efficiency of resources- there are always examples that are as bloated as they can be for the contemporary available resources. Same with all computer programs. Designing and implementing these things for efficiency has never been the majority goal there.
Re: Memory leaks and web browsers
by on (#117672)
rainwarrior wrote:
Webpages are generally designed without concern for the efficiency of resources- there are always examples that are as bloated as they can be for the contemporary available resources.

For one thing, "contemporary available resources" can range down to an Atom netbook or an ARM tablet or smartphone. See discussion about frustration with garbage collection overhead in web browsers on slow, RAM-starved mobile devices.

Quote:
Same with all computer programs. Designing and implementing these things for efficiency has never been the majority goal there.

The server side of a popular web application may need to serve several customers per second on each server behind the load balancer. Or a game for a late-generation console or handheld game system may try to raise scene complexity compared to competitors' games.
Re: Memory leaks and web browsers
by on (#117675)
I had an issue with Chrome a year ago where certain tabs would leak 400k or so of memory per second while they were in the background. This included very simple web pages from the 90s and would go to the point where one page was using over a gigabyte. I think part of the problem had to do with trying to cache every single decoded frame of an animation as it was running, even when it was offscreen.
Re: Memory leaks and web browsers
by on (#117681)
tepples wrote:
For one thing, "contemporary available resources" can range down to an Atom netbook or an ARM tablet or smartphone. See discussion about frustration with garbage collection overhead in web browsers on slow, RAM-starved mobile devices.

The server side of a popular web application may need to serve several customers per second on each server behind the load balancer. Or a game for a late-generation console or handheld game system may try to raise scene complexity compared to competitors' games.


Yes, as always there are applications which require lighter / optimized implementations. Doing this is a specialized skill, and it's not needed for most cases. The majority of people take the naive path, and either don't have a problem at all because their task is incomplex, or don't notice the poor performance of their stuff because it's not really an issue to them, and/or they don't care about how it runs on more limited platforms that they don't use themselves.

For example, the recently released Hate Plus visual novel game has horrendous performance, and it uses all available CPU on its thread at all times even though it is largely just static screens of text. It causes a mild annoyance for people playing it (lag between input and feedback, jerky transitions, etc.), and I suppose causes a waste of electricity, heats up my laptop and gets that fan going annoyingly loud, etc. but it doesn't make the game non-functional at all. All these things annoy me, and the issue is probably really easy to fix for a programmer who is specialized in optimization, but it's not enough of a problem that its author is going to solve it. I'm not trying to single out Hate Plus, it's just an example-- a great deal of indie games have very poor performance for what they do.

There have always been programs and games and websites that run slowly and use way too much memory. Yes, resources were a bit tighter in the past, but the result was just that people managed to accomplish less complicated things before they hit their performance barrier. There was never a good old days when people cared more about performance, that's always been specialized.
Re: Memory leaks and web browsers
by on (#117683)
The important difference is that Moore's Law used to mean that "Uses all the resources of 3-year-old hardware" would imply "Works fantastically on current hardware". Not true anymore.
Re: Memory leaks and web browsers
by on (#117687)
The solution to something that unnecessarily uses 100% CPU usage is to dive in with OllyDbg, and find out where it's wasting all the time.
Then insert Sleep(1) there, and watch the CPU usage go down to 1%.
Re: Memory leaks and web browsers
by on (#117694)
Unless it's spinning on vsync, in which case Sleep(1) may result in visible tearing.
Re: Memory leaks and web browsers
by on (#117701)
Well, in the case of Hate Plus it's because RenPy has an option to limit the framerate that the author of the game did not enable. Apparently it's off by default, so unfortunately the naive user gets 100% CPU usage.

Thanks for mentioning OllyDbg though, this looks neat. I'd never heard of it.