Adblock Plus and (a little) more

Raymond Chen quote of the day · 2012-01-05 19:59 by Wladimir Palant

When DLL_PROCESS_DETACH tells you that the process is exiting, your best bet is just to return without doing anything:

I regularly use a program that doesn’t follow this rule. The program allocates a lot of memory during the course of its life, and when I exit the program, it just sits there for several minutes, sometimes spinning at 100% CPU, sometimes churning the hard drive (sometimes both). When I break in with the debugger to see what’s going on, I discover that the program isn’t doing anything productive. It’s just methodically freeing every last byte of memory it had allocated during its lifetime.

Somehow I have the impression that I know which program he talks about. While I understand why Firefox/Gecko is doing this and that fixing this issue would require pretty complicated and dangerous architectural changes, I wonder whether there is some relatively simple partial solution. For example, what about modifying the free() function of the custom memory allocator used by Firefox to just stop doing anything when the process is exiting? It shouldn’t have any noticeable effect on anything: objects will still be “released” when their ref count reaches zero and their destructors will still run but the memory management overhead at shutdown will go away. But of course I don’t know how much of the shutdown delay is caused by the memory management and how much of it is simply destructors hugging object data one last time.

Tags:

Comment [4]

  1. Kyle Huey · 2012-01-05 20:37 · #

    Er, I think you’re seriously confused. Which isn’t surprising, because Raymond’s post is also seriously confused. Not doing cleanup at shutdown is distinct from not doing cleanup in DllMain when DLL_PROCESS_DETACH is called. The latter is much worse and can actually deadlock your program and is not something we do. The former is just arguably wasteful. I’m not sure why Raymond is confusing these two things.

    Reply from Wladimir Palant:

    Not sure what you mean but releasing memory one object at a time is clearly wasteful if the OS will release all your memory anyway.

  2. Jesse Ruderman · 2012-01-05 20:42 · #

    Bug 662444 – Shutdown by exit(0), skip GCs and other unneeded operations

    Reply from Wladimir Palant:

    Nice! I was sure that I was missing something :)

  3. Archaeopteryx · 2012-01-05 23:27 · #

    Shutdown record: 53 minutes (3.6.x – on Gecko 2 I can’t keep it open long enough to get such shutdown times).

  4. chat · 2012-01-10 12:12 · #

    Memory trouble in this article was very helpful thank you.

Commenting is closed for this article.