You are not logged in.

#1 2012-07-12 19:30:52

Gullible Jones
Member
Registered: 2004-12-29
Posts: 4,863

Dealing with memory leaks

Say I have a program with a memory leak. It does not allocate all my RAM and more in one go. Instead it accumulates small allocations that it uses and never frees up, until eventually it exceeds available free RAM. At this point one of three things happens.

1. I'm using swap space. My system grinds to a complete halt, and I have to force a reboot a la Classic Mac.

2. I'm not using swap. System freezes for a second, and then stuff starts crashing, including the entire desktop if I'm unlucky.

3. I'm using zram swap. System freezes for ten seconds, then all hell breaks loose as per (2).

None of these things are really a good result. It would be better for the leaky program to crash, and leave everything else alone.

How could I manage that? Is it possible to e.g. specify a maximum allowable physical memory usage per process?

Offline

#2 2012-07-12 19:42:47

ewaller
Administrator
From: Pasadena, CA
Registered: 2009-07-13
Posts: 19,739

Re: Dealing with memory leaks

Gullible Jones wrote:

Say I have a program with a memory leak.

Fix it?
Is it your code, FOSS, or *ahem* other?
valgrind is a great tool for finding leaks.  You have to plug them though.


Nothing is too wonderful to be true, if it be consistent with the laws of nature -- Michael Faraday
Sometimes it is the people no one can imagine anything of who do the things no one can imagine. -- Alan Turing
---
How to Ask Questions the Smart Way

Offline

#3 2012-07-12 20:38:40

Gullible Jones
Member
Registered: 2004-12-29
Posts: 4,863

Re: Dealing with memory leaks

Not mine, not FOSS, not maintained.

Offline

#4 2012-07-12 20:47:45

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 29,445
Website

Re: Dealing with memory leaks

Gullible Jones wrote:

Is it possible to e.g. specify a maximum allowable physical memory usage per process?

I'm not sure if there is any practical way to do this, but even if there was, I doubt it would solve anything.  How would you chose what this maximum would be so that it would allow all the "well behaved" but memory using programs (maybe gimp or libreoffice) to work, but stop the other program from using too much?  Also, this would not slow a multithreaded program that eats memory by adding processes which many memory intesive apps often do (eg, many web browsers).


"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" -  Richard Stallman

Offline

#5 2012-07-12 21:25:39

briest
Member
From: Katowice, PL
Registered: 2006-05-04
Posts: 468

Re: Dealing with memory leaks

ulimit? See https://wiki.archlinux.org/index.php/Re … efinitions for limits description and your-favourite-shell man for ulimit builtin syntax. Although for some time you cannot set physical RAM limit, limiting whole address space works.

Offline

#6 2012-07-12 21:51:37

ignorant
Member
Registered: 2012-06-09
Posts: 50

Re: Dealing with memory leaks

Gullible Jones wrote:

Say I have a program with a memory leak. It does not allocate all my RAM and more in one go. Instead it accumulates small allocations that it uses and never frees up, until eventually it exceeds available free RAM. At this point one of three things happens.

If you somehow prevented the process from calling sbrk(2) successfully and expanding the heap, the program would probably break because of it. A malloc would fail and, depending on how the program handles that error, it might just exit right there. So it's not like the program would stay working anyway. It obviously thinks it needs that memory and if the OS says there's no more memory, the program will probably bail right there.

Gullible Jones wrote:

Not mine, not FOSS, not maintained.

Are you sure there isn't an alternative somewhere?

Offline

Board footer

Powered by FluxBB