Re: Prolog, memory management and memory leaks



On 2008-01-29, Mats <matsc@xxxxxxx> wrote:
In my experience, a more difficult kind of "memory leak" is memory
fragmentation. Many Prolog implementations manage their own memory;
others rely on malloc & free or similar. In both cases, memory can
easily become fragmented when the process has run for a long while,
filling the memory with blocks that are too small to be useful. Some
memory managers (SICStus's for example) coalesce adjacent free blocks
as far as possible, but I'm not aware of any Prolog that move blocks
around and completely defragment memory, which would be extremely
complex, what with all the necessary relocation and everything. The
only safe cure I know of is to restart the process.

This is indeed a problem I have seen, though Prolog isn't the only
language suffering. In fact, Prolog may not be that bad as lots of
things are allocated on the stacks and these are nicely compacted.
One does need to be careful with dynamic code, records and atoms
though. Dynamic code might often not be that bad as quite often it
uses asserts and retracts clauses of the same structure that happen to
result in a perfect match. Atoms are a bigger problem, especially if
code uses lots of long atoms (SWI-Prolog has no limit except for
available memory).

Many programs that run 24x7 execute a limited set of similar routines
frequently and for them memory often stops growing after a while.

--- Jan
.



Relevant Pages

  • Re: Prolog, memory management and memory leaks
    ... There was a myth than languages with garbage collector are free of ... I have Prolog application that is implemented as a "running forever ... predicate is executed that solves constraint problem. ... In some circumstances, this server leaks memory. ...
    (comp.lang.prolog)
  • Re: A few questions about Prolog...
    ... few Prolog implementations, and would appreciate if the community ... SWI-Prolog uses a lot of memory for stacks? ... unexpected is behavior of your program caused by programming error. ...
    (comp.lang.prolog)
  • Re: Prolog, memory management and memory leaks
    ... a more difficult kind of "memory leak" is memory ... Many Prolog implementations manage their own memory; ... memory, despite enough memory was available, but fragmentation was ... our ambition is to complete single session without restart. ...
    (comp.lang.prolog)
  • Re: A few questions about Prolog...
    ... few Prolog implementations, and would appreciate if the community ... SWI-Prolog uses a lot of memory for stacks? ... could find in favor of GNU-Prolog is a good choice of GUI. ...
    (comp.lang.prolog)
  • Re: Prolog, memory management and memory leaks
    ... a more difficult kind of "memory leak" is memory ... Many Prolog implementations manage their own memory; ... memory, despite enough memory was available, but fragmentation was ... our ambition is to complete single session without restart. ...
    (comp.lang.prolog)