Title: [Bug in PS 5,6 and 7] Memory leak when Select-Object on $Global scope array of PSCustomObject · Issue #11441 · PowerShell/PowerShell · GitHub
Open Graph Title: [Bug in PS 5,6 and 7] Memory leak when Select-Object on $Global scope array of PSCustomObject · Issue #11441 · PowerShell/PowerShell
X Title: [Bug in PS 5,6 and 7] Memory leak when Select-Object on $Global scope array of PSCustomObject · Issue #11441 · PowerShell/PowerShell
Description: Steps to reproduce function Initialize-Something { $Global:TestArray = @() $Global:TestArray += [PSCustomObject]@{abc=1;def=2} $Global:TestArray += [PSCustomObject]@{abc=2;def=3} $Global:TestArray += [PSCustomObject]@{abc=3;def=4} } func...
Open Graph Description: Steps to reproduce function Initialize-Something { $Global:TestArray = @() $Global:TestArray += [PSCustomObject]@{abc=1;def=2} $Global:TestArray += [PSCustomObject]@{abc=2;def=3} $Global:TestArray ...
X Description: Steps to reproduce function Initialize-Something { $Global:TestArray = @() $Global:TestArray += [PSCustomObject]@{abc=1;def=2} $Global:TestArray += [PSCustomObject]@{abc=2;def=3} $Global:TestArray ...
Opengraph URL: https://github.com/PowerShell/PowerShell/issues/11441
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"[Bug in PS 5,6 and 7] Memory leak when Select-Object on $Global scope array of PSCustomObject","articleBody":"# Steps to reproduce\r\n\r\n```\r\nfunction Initialize-Something {\r\n $Global:TestArray = @()\r\n $Global:TestArray += [PSCustomObject]@{abc=1;def=2}\r\n $Global:TestArray += [PSCustomObject]@{abc=2;def=3}\r\n $Global:TestArray += [PSCustomObject]@{abc=3;def=4}\r\n}\r\n\r\nfunction Invoke-Something {\r\n for($i=0; $i -lt 1000; $i++) {\r\n $Global:TestArray | Select-Object > $null\r\n }\r\n}\r\n\r\nInitialize-Something\r\nInvoke-Something\r\n```\r\n\r\n# Expected behavior\r\n\r\n```\r\nGarbage collection should clear heap afterwards\r\n```\r\n\r\n# Actual behavior\r\n\r\nEvery call to `Invoke-Something` collects more objects of the following type in managed memory:\r\n```\r\n{System.Collections.Concurrent.ConcurrentDictionary\u003cstring, System.Management.Automation.PSMemberInfoInternalCollection\u003cSystem.Management.Automation.PSMemberInfo>>.Node}\r\n```\r\n\r\n\r\n\r\n\r\nMost notably, the \"_key\" contains the following.\r\n> \"Selected.System.Management.Automation.PSCustomObject@@@Selected.System.Management.Automation.PSCustomObject@@@Selected.System.Management.Automation.PSCustomObject@@@Selected.System.Management.Automation.PSCustomObject@@@Selected.System.Management.Automation.PSCustomObject@@@Selected.System.Management.Automation.PSCustomObject@@@Selected.System.Management.Automation.PSCustomObject@@@Selected.System.Management.Automation.PSCustomObject@@@Selected.System.Management.Automation.PSCustomObject@@@Selected.System.Management.Automation.PSCustomObject@@@Selected.System.Management.Automation.PSCustomObject@@@Selected.System.Management.Automation.PSCustomObject@@@Selected.System.Management.Automation.PSCustomObject@@@Selected.System.Management.Automation.PSCustomObject@@@Selected.System.Management.Automation.PSCustomObject@@@Selected.System.Management.Automation.PSCustomObject@@@Selected.System.Management.Automation.PSCustomObject@@@Selected.System.Management.Automation.PSCustomObject@@@Selected.System.Management.Automation.PSCustomObject@@@Selected.System.Management.Automation.PSCustomObject@@@System.Management.Automation.PSCustomObject@@@System.Object\"\r\n\r\nAfter each run of `Invoke-Something`, every newly created object of the above type seems to inherit this list, but increased by one more `Selected.System.Management.Automation.PSCustomObject`. This creates an exponential growth, over time.\r\n\r\n\r\n# Environment data\r\n\r\n```\r\nName Value\r\n---- -----\r\nPSVersion 6.1.0\r\nPSEdition Core\r\nGitCommitId 6.1.0\r\nOS Microsoft Windows 10.0.18362\r\nPlatform Win32NT\r\nPSCompatibleVersions {1.0, 2.0, 3.0, 4.0...}\r\nPSRemotingProtocolVersion 2.3\r\nSerializationVersion 1.1.0.1\r\nWSManStackVersion 3.0\r\n```\r\n.. but the same happens with pwsh core 6.2.3, as well. Same thing happens, when running pwsh on a linux platform.","author":{"url":"https://github.com/RainbowMiner","@type":"Person","name":"RainbowMiner"},"datePublished":"2019-12-27T14:44:59Z","url":"https://github.com/PowerShell/PowerShell/issues/11441"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:1ef26968-08d7-0a91-7bb7-a587ba069f90 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | E608:248A71:192E0C:2377F8:6AFD4FFD |
| html-safe-nonce | 8ca66c176ed18fbd725867f3ac0cafd79cc530142cbf8e8bb04b8cee3f03e707 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFNjA4OjI0OEE3MToxOTJFMEM6MjM3N0Y4OjZBRkQ0RkZEIiwidmlzaXRvcl9pZCI6IjI1OTg4NDY2NTA2MDQ0MDg4MjkiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 0c6fda95ef0b988e9db95399b8acae86fd334d1f3e936a333e34970d1fc0ca2f |
| hovercard-subject-tag | issue:542897202 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/PowerShell/PowerShell/11441/issue_layout |
| twitter:image | https://opengraph.githubassets.com/d8b8dc47aea666b8923fc628a9370d878625ce23991ce5a0ed5cafaddb5d1992/PowerShell/PowerShell/issues/11441 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/d8b8dc47aea666b8923fc628a9370d878625ce23991ce5a0ed5cafaddb5d1992/PowerShell/PowerShell/issues/11441 |
| og:image:alt | Steps to reproduce function Initialize-Something { $Global:TestArray = @() $Global:TestArray += [PSCustomObject]@{abc=1;def=2} $Global:TestArray += [PSCustomObject]@{abc=2;def=3} $Global:TestArray ... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | RainbowMiner |
| hostname | github.com |
| expected-hostname | github.com |
| None | 66653c2e55a6fff2930be1bdf07ee4f8aa137e3956d056c822563be6f878755e |
| turbo-cache-control | no-preview |
| go-import | github.com/PowerShell/PowerShell git https://github.com/PowerShell/PowerShell.git |
| octolytics-dimension-user_id | 11524380 |
| octolytics-dimension-user_login | PowerShell |
| octolytics-dimension-repository_id | 49609581 |
| octolytics-dimension-repository_nwo | PowerShell/PowerShell |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 49609581 |
| octolytics-dimension-repository_network_root_nwo | PowerShell/PowerShell |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | b6f01f7cb9f35f8c09949773241a3d49dd04b340 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width