Windows Vista Forums

Memory Management in PowerShell?
  1. #1


    kc2kth Guest

    Memory Management in PowerShell?

    Is there any method short of exiting PowerShell and restarting it to release
    memory used by varialbes?

    For this example I'm using the Quest ActiveRoles commandlets, however I do
    not believe this is related to those commandlets specifically.



    If I do "$groups = get-qadgroup", which returns the first 1000 groups found
    in AD, I use roughly 6MB of memory. This isn't too bad by iteself. However if
    I were to pass the "-SizeLimit 0" parameter as part of the command the impact
    would be much more severe in larger environments. I witnessed the PowerShell
    process grow to over 300MB following a "$users = get-qaduser -SizeLimit 0"
    earlier.

    I tried two methods to release this memory. First I set $groups = $null,
    which had no impact. Next I tried "remove-variable groups". Again, no impact
    on memory utilization.

    Closing PowerShell does give back all of the memory. Is this the only way?

      My System SpecsSystem Spec

  2. #2


    Brandon Shell [MVP] Guest

    Re: Memory Management in PowerShell?

    Powershell is a managed App... The GC process should clean up memory.

    After you remove the variable try this

    # This will force the Garbage Collection Process
    [GC]::Collect()

    And then check again

    Brandon Shell
    ---------------
    Blog: http://www.bsonposh.com/
    PSH Scripts Project: www.codeplex.com/psobject

    k> Is there any method short of exiting PowerShell and restarting it to
    k> release memory used by varialbes?
    k>
    k> For this example I'm using the Quest ActiveRoles commandlets, however
    k> I do not believe this is related to those commandlets specifically.
    k>
    k> If I do "$groups = get-qadgroup", which returns the first 1000 groups
    k> found in AD, I use roughly 6MB of memory. This isn't too bad by
    k> iteself. However if I were to pass the "-SizeLimit 0" parameter as
    k> part of the command the impact would be much more severe in larger
    k> environments. I witnessed the PowerShell process grow to over 300MB
    k> following a "$users = get-qaduser -SizeLimit 0" earlier.
    k>
    k> I tried two methods to release this memory. First I set $groups =
    k> $null, which had no impact. Next I tried "remove-variable groups".
    k> Again, no impact on memory utilization.
    k>
    k> Closing PowerShell does give back all of the memory. Is this the only
    k> way?
    k>



      My System SpecsSystem Spec

  3. #3


    kc2kth Guest

    Re: Memory Management in PowerShell?


    Perfect.

    And thanks for the quick response!

    "Brandon Shell [MVP]" wrote:

    > Powershell is a managed App... The GC process should clean up memory.
    >
    > After you remove the variable try this
    >
    > # This will force the Garbage Collection Process
    > [GC]::Collect()
    >
    > And then check again
    >
    > Brandon Shell
    > ---------------
    > Blog: http://www.bsonposh.com/
    > PSH Scripts Project: www.codeplex.com/psobject
    >

      My System SpecsSystem Spec

Memory Management in PowerShell? problems?

Similar Threads
Thread Thread Starter Forum Replies Last Post
Vista runs out of physical memory when working with files > 1GB - memory management issue? Robert Janik Vista performance & maintenance 2 21 Apr 2010
Memory Management zhen90 General Discussion 0 21 Nov 2009
Memory Management ChuckN Vista General 0 18 Aug 2008
Memory Management Brad Vista hardware & devices 6 23 Oct 2007
Bad memory management? Erik Wikström Vista performance & maintenance 6 12 Jul 2006