-
1. Re: KnowledgeBase keeps links to stateful sessions after disposing
tsurdilovic Dec 7, 2011 6:21 AM (in response to sshyika)I can assure you that there are no known memory leaks in Drools, especially something what is as core of functionality as session management. Please debug your code some more, as the problem lies there. After debugging, if you have concrete questions/info then please post them.
-
2. Re: KnowledgeBase keeps links to stateful sessions after disposing
sshyika Dec 7, 2011 8:32 AM (in response to tsurdilovic)Hi, Tihomir, thank you for reply. I am observing memory leak with stateless sessions too. Here is simple code below:
public static void main(String... args) {
KnowledgeBase base = KnowledgeBaseFactory.newKnowledgeBase();
waitForKeyPress();for (int i = 0; i < 500; i++) {
StatelessKnowledgeSession session = base.newStatelessKnowledgeSession();
session.execute(buildHeavyObject());
}
System.out.println("Finished");
waitForKeyPress();
}
private static Object buildHeavyObject() {
List<Date> list = new ArrayList<Date>();
for (int i = 0; i < 1000; i++) {
list.add(new Date());
}
return list;
}
private static void waitForKeyPress() {
try {
System.in.read(new byte[2]);
} catch (IOException e) {
e.printStackTrace();
}
}
Here we simply create 500 stateless sessions and insert in each "heavy" object (list of 1000 dates).
Below is jConsole screenshot made while programm waiting for second key press:
As you can see java process consumes ~3Mb before and 22Mb after invoiking sessions.
Below is a screenshot of my debugger, that was made after invoiking sessions:
You can see that knowledge base keeps 500 references to ProcessRuntime objects.
The picture is the same when we using statefull sessions and dispose them by dispose() method.
-
3. Re: KnowledgeBase keeps links to stateful sessions after disposing
tsurdilovic Dec 7, 2011 8:39 AM (in response to sshyika)Your sample code uses stateless sessions, not stateful, so not sure where dispose applies here. Stateless sessions are fire-and-forget. So once you execute it, you should set it to null in your example, otherwise yes the reference to it will keep existing.
-
4. Re: KnowledgeBase keeps links to stateful sessions after disposing
sania Dec 7, 2011 11:44 AM (in response to tsurdilovic)It won't change anything if you set variable "session" to null because it's visibility scope is limited by for operator. And if you look at screenshot you will see that garbage collecter can't free session memory because KnoledgeBase is referencing those sessions, not Main method.