powershell - Session Info in global variables -


i have function in powershell, establishes session , stores info in global variables:

$global:transport = new-object fix.serversockettransport $fixhost, $fixport 

now, within application $global:transport variable used send , receive data.

after script execution ends session closed? $global:transport value reset? (i have commented out part disconnect session)

after script ends, though not create new session, sends , receives data through $global:transport variable. why happen?

globals indeed global session. after script executes (and creates global) variable , value persists. btw powershell / .net not automatically close objects. if object implements finalizer when collected via garbage collection (at indeterminate time in future) finalizer run , close or release associated native resources. if object implements idisposable or otherwise has close() or dispose() method on it, should call method when you're done object. also, in order keep powershell hanging onto object forever (you did put in global), can either a) set global variable $null or b) (and better) remove variable altogether using remove-variable.

another option create script scope variable in outter script (startup script). script variable should visible other scripts execute , go away when script finished. however, in case above, if object implement close() or dispose() should call on object when you're done it.


Comments

Popular posts from this blog

apache - Remove .php and add trailing slash in url using htaccess not loading css -

javascript - jQuery show full size image on click -