PowerShell / PowerShell/PowerShellEditorServices
Clear secondary streams on primary PowerShell object
Nobody has claimed this yet.
- Dominant language
- C#
- Stars
- 767
- Forks
- 266
- Avg merge
- 3d 16h
- Merged PRs (30d)
- 1
Description
Currently we reuse the same PowerShell object for every script invocation/prompt evaluation, but we aren't clearing the streams afterward. Example:
PS> $context = $psEditor.Components.Get([Microsoft.PowerShell.EditorServices.PowerShellContext])
PS> $ps = $context.GetType().GetField('powerShell', 60).GetValue($context)
PS> $ps.Streams.Information
# <Empty>
PS> Write-Host 'first message'
PS> $ps.Streams.Information
# first message
PS> Write-Host 'second message'
PS> $ps.Streams.Information
# first message
# second message
Same for the other streams e.g. warning, verbose, debug, and progress (even though progress is not shown, the record is still stored until the end of the session)
Depending on how long the PSIC is left open and how much these streams are being written to, this could be the cause of some reported memory usage issues.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start at the code that reuses the primary PowerShell object for script invocations and prompt evaluations, then inspect its Streams.Information, warning, verbose, debug, and progress collections. Reproduce the accumulation shown in the issue and trace when each invocation completes. Done means secondary stream records do not persist across invocations, including progress records, and the behavior is covered by the relevant tests if present.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp, powershell
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100