Memory usage

瀏覽次數:69 次
跳到第一則未讀訊息

Erin Loy

未讀,
2020年1月26日 下午3:13:382020/1/26
收件者:NRules Users
I'm new to NRules (very cool project), and I've been playing around with a simple rule that adds two values.  I've noticed that when I use a single repository many times in a loop, the process memory usage grows indefinitely, even though I'm removing the facts after each operation.  When I recreate the repository in each loop, memory does not grow.

Here my test code that demonstrates this:

It seems to be related to executing a query against the session to retrieve the result.

Thoughts?

2020-01-26 12_07_55-NRulesTest - Microsoft Visual Studio.png



2020-01-26 11_35_57-Clipboard.png

Sergiy Nikolayev

未讀,
2020年2月13日 凌晨12:24:432020/2/13
收件者:NRules Users
This is interesting. I profiled it, and it turns out it is this line in Processor.Add method:
return session.Query<Property<T>>().Single();

ISession.Query returns IQueryable, which uses Expressions. So, it gets compiled in a tight loop, creating various objects related to IL generation.
When you moved the processor inside the tight loop, it became so slow (as it needs to compile the rules and build the session factory) that you no longer noticed the footprint growing.
It also does not really leak memory, but all these objects sit in a finalizer queue. So, if memory pressure got really high, all that stuff would have gotten reclaimed.
回覆所有人
回覆作者
轉寄
0 則新訊息