Memory runaway with Pooled resources
I'm not sure if I'm misusing the system somewhere, but it appears that every call to ExecuteAsync is re-adding the HostObjects, so pooled engines end up with thousands of attachments. We were using Evaluate on individual engines to resolve expressions, but using the manager we have to use ExecuteAsync, and we don't get access to the engine until the task returns. As objects are passed in through options, it's not possible to identify if they are already attached to that pooled engine. Anyway, to cut a long story short, after a few thousand operations we run out of memory on the engines and the system slows to a crawl. The pooling and hosting system is excellent, and protects us from many potential disasters such as infinite loops and memory overload (almost), and this is our only current sticking point.
Ideally we would like to pass an expression for evaluation thousands of times to a pre-configured engine with the appropriate scripts and libraries pre-loaded, but in this system it appears we have to include our expression as a script, then access it afterwards from a Script variable or a Host attached object. In our latest test we had 13,000+ objects in the engine's hostObjectHostItemCache.Keys collection, and we don't add any ourselves! They are all {ClearScript.Manager.Loaders.Requirer} targets, and all appear to be duplicates. Given that these are added by the user, shouldn't they be cleared each time an engine is retrieved from the pool?
Cheers, Jason