keyongtech


  keyongtech > windows.* > windows.powershell > 07/2009

 #1  
07-10-09, 09:53 PM
ioioio322
Using Powershell v1 atm..

I'm working on a large complex script and need to be able to destro
objects, specifically ArrayLists. How can I do so

This is how I create ArrayLists in Powershell
$arrayList = New-Object System.Collections.Arraylis

How do I destroy it
 #2  
07-10-09, 10:19 PM
Mike Pfeiffer
Remove-Variable arrayList

"ioioio322" wrote:
[..]
 #3  
07-12-09, 12:40 AM
ioioio322
Thank You. It doesn't work.

Is this for Powershell v2.0? I am using Powershell v1.0.

Are you sure you can use this to delete an OBJECT? An ArrayList is an
object... not a variable (a primitive)...
 #4  
07-12-09, 06:00 AM
Joel Bennett
Sorry if this is too basic, but ...

In .Net (and therefore, in PowerShell), you don't really "Destroy"
things unless they are using "real" resources like file handles...

In the case where you have such an object, it implements IDisposable,
which means you can get rid of if by calling $foo.Dispose()

An ArrayList, however, is not disposable.

..Net (and therefore, PowerShell) has a garbage collector -- this means
that anything to which there are no more references will be deleted for
real. The usual simple way of removing references to things is to just
null out the variable, eg:

$list = New-Object System.Collections.ArrayList
$list = $null

Obviously that doesn't actually get rid of the ArrayList, just your
pointer to it (particularly if in between, you made another variable
point to it, or set it as the property of an object).

Remove-Variable simply deletes a variable and its value from the scope,
so it basically does the same thing as setting it to null, except that
the variable will also no longer show up if you list the contents of the
Variable:\ drive. In either case, the next time the garbage collector
runs, the memory will be collected and returned to the system.

If this doesn't help, you're going to have to be more explicit about
what the actual symptoms are that you're trying to cure ;)
Similar Threads
Does the clone() method of ArrayList<> make a copy of the objects in the ArrayList?

anotherArrayList = (ArrayList<Something>) oneArrayList.clone(); anotherArrayList.get(0).makeSomeChange(); Will the change made in the second line make effect...

Combo box bound to Arraylist showing class name of objects in arraylist rather than Value/DisplayMembers

I am binding a combo box to an array list and the combo box is showing the name of the class objects in the ArrayList rather than the ValueMember and the DisplayMember. The...

How to do recursive objects enumeration - e.g. Get IPAddress from ArrayList of Socket objects

In VS you can expand the collection and then expand the sub objects (and so on) How can I do it in windbg + sos.dll Consider the following cacses If I have: 1. Socket[] 2....

SOS.dll: How to do recursive objects enumeration - e.g. Get IPAddress from ArrayList of Socket objects

Copied from: [..] In VS you can expand the collection and then expand the sub objects (and so on) How can I do it in windbg + sos.dll

copying an arraylist of objects into an array of the objects themselves.

If this makes sense, I would like to convert an arraylist of objects returned from foo() into an array of the objects themselves per; private Customer[] customers; private...


All times are GMT. The time now is 09:48 PM. | Privacy Policy