Re: Prolog, memory management and memory leaks
- From: Jan Wielemaker <jan@xxxxxxxxxxxxxxxxxxx>
- Date: 26 Jan 2008 16:44:35 GMT
On 2008-01-26, A.L <alewando@xxxxxxxxxxxx> wrote:
Well, we know that memory leaks are everyday business when programming
in C++.
There was a myth than languages with garbage collector are free of
this problem. Of course, until someone leaves forgotten reference to
10 MB of stuff..
How is in Prolog?... Are memory leaks possible?
There is no easy answer, and definitely not if you want it to be
`generic'.
I have Prolog application that is implemented as a "running forever
server", and has rather simple structure
a) some facts are asserted. These facts contain data of some
constraint problem
b) predicate is executed that solves constraint problem. This
predicate asserts list with results,
c) more predicates are executed that retrieve results from this list
d) When everything is done, cleanup predicate is called than retracts
all facts and result list.
In some circumstances, this server leaks memory.
I did the homework - I checked about a dozen papers on Prolog GC and
memory management. In one, "Understanding Memory Management in Prolog
Systems" by Castro and Costa, there is Table 3 that shows "garbage
collector efficiency". According to this table, GC efficiency for
non-deterministic predicates in not always perfect.
Questions:
1. Is memory leak in the scheme mentioned above possible? If yes, when
and why?
There is not just one garbage collector in Prolog. Typically Prolog
systems refer to the stack garbage collector when they state `garbage
collector'. This one is supposed to be `perfect', provided you either
use a failure driven loop or a deterministic tail-recursive loop. Prolog
GC generally deals with cyclic terms (if the Prolog system itself deals
with them).
I don't think there is a single estabished tradition to GC clauses from
dynamic predicates. SWI-Prolog for example GCs clauses on predicate
basis if the predicate is sufficiently dirty and there is no open
choice point on it. The predicate itself is never deleted. Neither are
name/arity pairs nor modules. Atoms are subject to atom garbage
collection.
2. What is the strategy to manage memory in long-running Prolog
applications?...
Typically, I'd say the main loop must be failure-driven or subject to
last-call optimization. Dynamic code and records must be
retracted/erased by the user (a good alternative is not to create any
:-). The user should not keep creating new predicates, name/arity pairs
or modules. Under those constraints you should be fine with SWI-Prolog
and I believe similar constraints hold for most Prolog systems.
I am asking these questions as "generic" ones, not regarding any
specific Prolog implementation.
The Prolog standard doesn't specify any of this ...
--- Jan
.
- Follow-Ups:
- Re: Prolog, memory management and memory leaks
- From: A . L .
- Re: Prolog, memory management and memory leaks
- References:
- Prolog, memory management and memory leaks
- From: A . L .
- Prolog, memory management and memory leaks
- Prev by Date: Re: Prolog, memory management and memory leaks
- Next by Date: Re: Prolog, memory management and memory leaks
- Previous by thread: Re: Prolog, memory management and memory leaks
- Next by thread: Re: Prolog, memory management and memory leaks
- Index(es):
Relevant Pages
|
Loading