I have got a problem with the physical memory in use by SWI prolog when asserting and then retracting clauses. In a nutshell, when I retract asserted clauses, the physical memory in use does not decrease. This is a problem when asserting and retracting a large number of clauses and the program is not meant to terminate (in an online setting using a server for instance).
Here an example:
:- dynamic myRelation/2.
test(N) :-
retractall(myRelation(_, _)),
loopAssert(N),
loopFind(N),
retractall(myRelation(_, _)), !.
loopAssert(0).
loopAssert(N) :-
get_time(Time),
asserta(myRelation(N, Time)),
M is N-1,
loopAssert(M).
loopFind(0).
loopFind(N) :-
myRelation(N, _Time),
M is N-1,
loopFind(M).
If I query “test(10000000)”, then I can see that at the termination of the program the physical memory in use does not decrease. By opening windows 10 Task Manager, I can see that 2,076 MB of memory remains in use at termination, and it stays like this. May I kindly as: why? And is there any workaround?
I’m using: SWI-Prolog version 8.2.3.