Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

8
  • 2
    \$\begingroup\$ "Leaks memory and system handles like crazy" What, do you have to free() them after? delete[], maybe? :P \$\endgroup\$ Commented Mar 28, 2016 at 15:25
  • 8
    \$\begingroup\$ @tac Yeah, there's a whole slew of .close() and .dispose() methods we're not calling here that would cause people on Code Review to have a fit. \$\endgroup\$ Commented Mar 28, 2016 at 15:27
  • \$\begingroup\$ Oh, isn't PS GC'd? Or does the GC do refcounting and not scope-analysis? \$\endgroup\$ Commented Mar 28, 2016 at 15:28
  • \$\begingroup\$ @tac Yes, PowerShell does have garbage collection thanks to the underlying .NET system. But, depending on how you're calling or leveraging this script, you can run into bugs like this one leaking memory in the pipeline. The above code also isn't thread-safe, and so can run into GC issues with that, since we're not explicitly closing the socket. \$\endgroup\$ Commented Mar 28, 2016 at 15:40
  • 1
    \$\begingroup\$ In testing I could not get this to work, likely due to firewall issues that I don't feel like fixing so I cannot be sure but..... I think you can drop "System" from most if not all the type casts you have there ie: [Net.ipaddress]::Any works. \$\endgroup\$ Commented Mar 28, 2016 at 16:21