-
Notifications
You must be signed in to change notification settings - Fork 81
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Symbols are stored globally and never freed. #203
Comments
Workaround for if you have the problem using multiprocessing.pool.Pool in Python: https://stackoverflow.com/questions/38294608/python-multiprocessing-pool-new-process-for-each-variable. Documentation: https://docs.python.org/3/library/multiprocessing.html#multiprocessing.pool.Pool |
Just be careful when exchanging data between the workers. The classes in the clingo API do not support pickling (and it would defy the attempt to safe memory). If you restrict yourself to python classes for communication, then these can be passed around easily and they will be freed when no longer referenced. |
@rkaminsk Are symbols freed when a clingo Control object is garbage-collected? E.g.: import clingo
# Abstraction of long-running business logic
while True:
clingo_control = clingo.Control()
clingo_control.load(...)
for _ in range(3):
clingo_control.ground((
...
))
for model in clingo_control.solve(yield_=True, async_=True):
for symbol in model.symbols(shown=True):
... |
No, they are never freed and actually shared between multiple control objects. |
While a garbage-collection/reference-counting approach of individual symbols is probably the ideal solution, is it possible count references to |
It is not that easy. The python program might store some other symbol objects. I can have a look if I can provide a function to clear all symbols. But it would be dangerous to use... |
Hmm. It's probably better to be memory-safe than to provide a function that could result in a segfault. I think some form of memory management is going to be an essential feature for real-world applications, but I can look into using subprocesses in the meantime. |
Is there a way with the C/C++ API to do that? It would be really helpful to at least have a manual option, even if the Python binding doesn't support it. |
The next major clingo release will give more control about storing symbols. For now there is no way to delete them - not even on the C++ level. |
@rkaminsk That is really nice to read. You once mentioned that this feature has to be well planned. Can you elaborate on how you plan to do it? |
Clingo internalizes symbols in global hash tables to only allocate memory for the same symbol once. Currently, symbols are never removed form this hash table. When an application runs for a long time and generates a lot of different symbols, this can lead to memory problems.
Unused symbols should be freed. This could be done via some form of garbage collection or reference counting.
The text was updated successfully, but these errors were encountered: