Skip to content
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

Need some help about the GC of KnowledgeEngine #21

Open
penspencap opened this issue Jan 19, 2020 · 1 comment
Open

Need some help about the GC of KnowledgeEngine #21

penspencap opened this issue Jan 19, 2020 · 1 comment
Assignees
Labels
bug Something isn't working

Comments

@penspencap
Copy link

I use the KnowledgeEngine as my Rule Engine. but the instance Of Light() ect would not actually release in memory.

I use it with a loop and at least 10000 user which has a large number Fact. The amount of memory will raise very quickly and be killed because of the memory is not enough.

Try to use gc.collect(). But it has the same result. And I need some help about that. Thanks.

This is my test sample of Light() has not be release in memory after the loop. And I use objgraph package for checking it .

# here's the demo code use by a loop
from random import choice
from experta import *

class Light(Fact):
    """Info about the traffic light."""
    pass

class RobotCrossStreet(KnowledgeEngine):
    @Rule(Light(color='green'))
    def green_light(self):
        print("Walk")

    @Rule(Light(color='red'))
    def red_light(self):
        print("Don't walk")

    @Rule(AS.light << Light(color=L('yellow') | L('blinking-yellow')))
    def cautious(self, light):
        print("Be cautious because light is", light["color"])


def test_func():
    engine = RobotCrossStreet()
    engine.reset()
    engine.declare(Light(color=choice(['green', 'yellow', 'blinking-yellow', 'red'])))
    engine.run()
    # will do some record..


if __name__ == '__main__':
    import objgraph

    objgraph.show_growth()
    for i in range(10):
        test_func()
    print('======after======')
    objgraph.show_growth()

# the first print of show_growth()
'''
function                       2389     +2389
dict                           1211     +1211
wrapper_descriptor             1043     +1043
tuple                           831      +831
builtin_function_or_method      789      +789
method_descriptor               743      +743
weakref                         731      +731
getset_descriptor               455      +455
member_descriptor               299      +299
type                            231      +231
'''

# the second print of show_growth
'''
dict                           1311      +100
weakref                         786       +55
set                             155       +46
builtin_function_or_method      821       +32
FactCapture                      30       +30
list                            209       +29
Light                            32       +29    <---- here
tuple                           858       +27
method                           43       +15
ChildNode                        15       +15
'''
@nilp0inter
Copy link
Owner

Hi, thank you for reporting this. I will take a look at it ASAP.

@nilp0inter nilp0inter added the bug Something isn't working label Feb 3, 2020
@nilp0inter nilp0inter self-assigned this Feb 3, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants