views:

589

answers:

2

Hi, I'm automating the usage of powershell scripts from C# using the powershell async pipeline invoke and I notice that when I execute script over and over again, using the same runspace, the .vhost.exe memory usage goes up and up and up, and it would run out of memory after a days operations.

Is there a way to measure how much memory has been claimed by the runspace, or indeed, is that even the way you would measure it. I know I could prepare a special script, which called out to WMI, and that would return a list of processes, I could search for the correct vhost, and then substring the specific line, but I think that is only adding to the prob.

I was thinking maybe the runspaceconfiguration class or the $host variable would offer summat up, but I can't see anything.

Ideally I would want to size the memory allocated to it, and once it got that size I would dispose of it, and create a new runspace, but that is expensive. Is their away to release the memory via, say a powershell dispose.

Any help would be appreciated.

26.05.2009

Hi, What I want to really know is how memory is used when execution multiple scripts over long periods affects the run time memory. Essentially I have an execution engine which is driven by rules. When a rule fires sometimes a script is executed. Each rulebase (set of rules) will have their own powershell host. The question is if I execute multiple scripts, how would that effect memory is the current appdomain. Would it be better to dump the host in another appdomain, or does it setup it's runtime outside the current standard c# way of doing it. Problem is, their is such a lack of good docs. Esssentially I want to be ensure their is not a buildup of memory usage, through repeated use. If I fire it into a remoted domain, then at least when it gets to a certain size, I can dump it, and recreate it.

Whats your thought. I'm mainly in the dark. Bob.

A: 

I think you will need to post a code snippet of exactly how you are using the powerscript objects to do this.

Also, VSHost is only the host process when you are running from the IDE (debugging in other words) Do you have the same situation when running the app outside the IDE?

Tim Jarvis
+1  A: 

One of the first areas to check would be that any objects you create in that runspace are dereferenced (no variables pointing towards them) so they can be garbage collected.

A similar issue can happen in the PowerShell console and I blogged about that problem here.

Steven Murawski