I've been using PyCLIPS in a project and ran into an issue where CLIPS would occasionally segfault while running. In an attempt to track the issue down, I started running a test case in a loop over and over again and noticed increasingly long run times.
At the beginning of each loop, I'd perform a clips.Reset(), a number of asserts, and a clips.Run(). However, I noticed that the CLIPS call to RemoveGarbageFacts() would take longer and longer with each call -- and it appeared that the linked list of facts maintained by CLIPS continued to get longer and longer.
RemoveGarbageFacts() checks the busyCount of each fact to determine whtehr or not it is still in use before performing cleanup and removing the fact from the list. I noticed that although I had used clips.Reset() and the EnvRetract() had been called on each of the facts, the busyCount was still non-zero as the garbage removal process took place.
It looked to me like the busyCount value was being double incremented when a clips.Assert() call took place. Looking more closely at the code, it appears that when clips.Assert() is used to place a fact into working memory, clips_fact_assign() in clipsmodule.c explicitly calls EnvIncrementFactCount(). This causes busyCount to increment one extra time, such that when my clips.Reset() is executed, the busyCount on each fact I've asserted never goes to 0 and is never cleaned up by the garbage collection.
I hope that makes sense! Thanks!
Regards,
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hello --
I've been using PyCLIPS in a project and ran into an issue where CLIPS would occasionally segfault while running. In an attempt to track the issue down, I started running a test case in a loop over and over again and noticed increasingly long run times.
At the beginning of each loop, I'd perform a clips.Reset(), a number of asserts, and a clips.Run(). However, I noticed that the CLIPS call to RemoveGarbageFacts() would take longer and longer with each call -- and it appeared that the linked list of facts maintained by CLIPS continued to get longer and longer.
RemoveGarbageFacts() checks the busyCount of each fact to determine whtehr or not it is still in use before performing cleanup and removing the fact from the list. I noticed that although I had used clips.Reset() and the EnvRetract() had been called on each of the facts, the busyCount was still non-zero as the garbage removal process took place.
It looked to me like the busyCount value was being double incremented when a clips.Assert() call took place. Looking more closely at the code, it appears that when clips.Assert() is used to place a fact into working memory, clips_fact_assign() in clipsmodule.c explicitly calls EnvIncrementFactCount(). This causes busyCount to increment one extra time, such that when my clips.Reset() is executed, the busyCount on each fact I've asserted never goes to 0 and is never cleaned up by the garbage collection.
I hope that makes sense! Thanks!
Regards,