Skip to content

Commit 4d05673

Browse files
author
Dave Wyatt
committed
Help update
Weak reference information in the about_PSLogging help topic.
1 parent 706bfa1 commit 4d05673

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

Module/PSLogging/en-US/about_PSLogging.help.txt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,17 @@ LONG DESCRIPTION
7676
Resume-Logging Resumes interceptor-to-subscriber calls.
7777

7878
Notes
79+
When creating new references to LogFile or OutputSubscriber objects, the calling script
80+
must maintain a reference to the resulting objects for as long as they intend the subscriber
81+
to remain active. As soon as the script releases the reference (either intentionally, or
82+
due to the variable falling out of scope), the subscriber object becomes eligible for garbage
83+
collection, and will be detached within a short time.
84+
85+
This is to make sure that subscribers don't remain active for an entire PowerShell session
86+
by mistake, if a script author forgets to call Disable-LogFile / Disable-OutputSubscriber,
87+
or if the script crashes before that cleanup code can be called. It is still possible for
88+
such objects to remain active after a script ends, if the script author chooses to place
89+
those variables in the Global scope.
7990

8091
This logging technique creates certain "circular reference" style situations which may
8192
cause infinite output to either the console, or worse, to a log file. For example,

0 commit comments

Comments
 (0)