Skip to content

Clear secondary streams on primary PowerShell object #791

Open
@SeeminglyScience

Description

@SeeminglyScience

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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions