5

这个问题是这个问题的后续

我在 Sicstus prolog 中运行大量测试:

runtest:-
 t1,
 t2,
 t3,
 .
 .
 t100.

每个测试都是独立的,并将其结果打印到屏幕上。测试之间没有关系,因此每次测试之间不需要存储/保存数据。

我的问题是 Sicstus 积累内存并最终遇到异常:'资源错误:内存不足'

我试图像这样组织我的测试:

runtest:-
  once( t1 ),
  once( t2 ),
  .
  .
  once( t100 ).

但我仍然遇到问题。

有没有其他方法可以告诉 Prolog 在每次调用测试之间释放所有分配的内存?

4

3 回答 3

5

不,没有办法告诉 Prolog 释放所有分配的内存。

如果测试谓词不带参数,并且将它们包装在一次/1 中没有帮助,那么故障驱动循环也不应该有帮助。

一种可能性是您的测试以某种方式添加了持久数据,例如断言子句。

尝试添加

垃圾收集,统计

在(一些)测试之间。这应该让您了解哪些内存区域正在增长。

从您之前的问题来看,可能是您的一个测试本身就耗尽了内存,即问题与运行多个测试无关。

于 2014-02-12T10:32:21.513 回答
3

尝试使用(现代)故障驱动循环:应该在任何Prolog上回收内存

?- forall(member(T, [t1,t2,...,t100]), once(T)).
于 2014-02-12T08:58:10.170 回答
2

The predicate once/1 only cuts away choice points, but leaves intact the trail. The trail is usually extended either by variable unifications or even by constraints of the constraint solvers.

So your chain of tests collects a lot of data. There is a Prolog folklore which would help you. Using double negation frees resources, this construct is therefore often nicknamed garbage collection.

Just rewrite your code to:

runtest:-
   \+ \+ t1,
   \+ \+ t2,
   \+ \+ t3,
   .
   .
   \+ \+ t100.

But please note that your test will now also measure the time to tear down the trail, possibly changing old results, since sometime the time to tear down the trail can be measurable.

And last but not least, of course the folklore garbage collection double negation only works when it is ok to call the goal once.

Bye

于 2015-11-01T01:17:35.540 回答