From the course: PowerShell for SQL Server Administration

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Disposing connections

Disposing connections - PowerShell Tutorial

From the course: PowerShell for SQL Server Administration

Start my 1-month free trial

Disposing connections

- [Instructor] Now, closing connections is very important. One other thing we need to do is disposing of connections and disposing of objects. So, all objects should obviously be closed, we just talked about that. So we also should be disposing objects as well so we can get those out of memory. So say we close a connection, that literally just terminates the connection to SQL Server, but we still have the memory in place for that object sitting in PowerShell. So PowerShell still owns that section of memory. So if we don't dispose of the object before we close the PowerShell script we have to wait for the garbage collector to come through and clean that up. So that could take a minute or two depending on how much memory our PowerShell script is using, that can end up being a decent amount of memory on a box just sitting, waiting for garbage collector to come through and clean things up. So we want to manually do that 'cause we want to be a polite person running our PowerShell script on…

Contents