Brian wrote:
Frederic Da Vitoria wrote> I think that Brian is asking if a memory leak could eat the system's> memory> irreversibly. IIUC in Windows, when the program is stopped, all it's> memory> is freed, even if the program leaked memory. I don't know about Linux, but> I'd be surprised if it weren't the same.> > -- > Frederic Da Vitoria> (davitof)> > Membre de l'April - « promouvoir et défendre le logiciel libre » -> http://www.april.org> > _______________________________________________> fpc-pascal maillist -
fpc-pascal@.freepascal
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Yes that is exactly what I was asking. For a high reliable system running24/7 
my fear using Object Oriented code vs procedural code is exactly whatyou 
mentioned . If there is a serious leak , or even a small one for anextended 
period of time , it can take down the OS. I have seen this happenwith Sun OS 
and a 3rd party driver that leaked and caused the OS to crashafter an extended 
period of time.

An operating system certainly /shouldn't/ crash if user processes allocate excessive memory. The overall system might thrash which would make it unresponsive to e.g. new SSH sessions, but that's hardly the same thing.

I've got stuff here running 24/7 with uptime measured in months. Historically, the memory leaks weren't in application code but were in database backend stuff that managed its own heap, which made it very difficult to monitor.

It's easy enough to code such that when you perform a complex activity which /should/ free all memory on completion you check that it does so. It's also easy enough to put something in your UI that reports how much is currently on the heap, and if you see that it's growing you can investigate in a development environment using e.g. HeapTrace.

In extremis, it's usually possible to get a program to restart itself if something's obviously wrong. I don't know if it's still the case, but Apache used to limit the number of requests each process would handle to protect it from memory loss due to faulty CGI etc.

If necessary, you can use a custom heap manager e.g. if you don't want it to expand beyond some preallocated size. In principle, you could code yourself multiple heaps each with custom procedures/functions, but while these might be useful for stuff that you're writing yourself you'll not be able to use them with the standard OO classes.

I don't believe that there's an equivalent to mark/release in the standard heap managers, and from discussion elsewhere I don't believe it could be added in a compatible way. Some variant of Mark() that took a parameter suggesting how much memory could be allocated could be useful, but your focus should be on preventing leaks and runaway rather than constantly recovering from them.

--
Mark Morgan Lloyd
markMLl .AT. telemetry.co .DOT. uk

[Opinions above are the author's, not those of his employers or colleagues]
_______________________________________________
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Reply via email to