I'd like to find a way to profile the memory usage of a predicate (a huge one) I've written in prolog. I'm currently running it with swi and yap and I can see from those processes memory consumption that a big chunk of memory gets allocated.
The problem is that it does not get deallocated/freed/garbage collected when the predicate terminates (I have to halt the interpreter to see it back) plus the amount of memory only keeps growing while the predicate is running (wheather it shall not since tail recursion optimization should mitigate the issue, I guess, at each iteration).
Is there a way to spot the subpredicate/call that increases the memory used and check if the tail recursion optimization is effectively being called?
Any other suggestion on how to optimize the issue will be very appreciated. I will give more details about what the predicate is doing if those are necessary.