We should consider removing the following variables:
PS> gv Max*Count
Name Value
---- -----
MaximumAliasCount 4096
MaximumDriveCount 4096
MaximumErrorCount 256
MaximumFunctionCount 4096
MaximumHistoryCount 4096
MaximumVariableCount 4096
They don't really protect the user from anything (it's easy to use up memory in many other ways) and they block some valid uses, e.g. if you add > 4096 functions in InitialSessionState
, the extra functions will be silently ignored - and there is no good way to increase that limit until after the runspace is open.
Agreed. I'd much rather see a consolidated "reporting" command that tells me how many of each I have (even better if it could display memory foot print). In case I need to debug a situation where too much memory is used for/by something. But even without that, yeah I'd be fine with removing these.
It's a very good idea.
I have some doubts about removing MaximumErrorCount
. It is very different
from the others and some limit makes sense. There may be a lot of errors in
some cases. This is bad for long running processes. Developers must keep
in mind that memory may leak via errors and care of this. Why?
Besides, when errors really have to be collected and analysed then use of
-ErrorVariable
parameter for a particular command is better than use of
$Error
which also may contain noise errors. -ErrorVariable
is unlimited.
Removing the max
value variable doesn't mean the error collection couldn't still be capped at a max size of 256. I guess the question in this case is - does anybody ever change (increase) that value
? I can't say that I have ever done that in 10+ years of using PowerShell.
Most helpful comment
It's a very good idea.
I have some doubts about removing
MaximumErrorCount
. It is very differentfrom the others and some limit makes sense. There may be a lot of errors in
some cases. This is bad for long running processes. Developers must keep
in mind that memory may leak via errors and care of this. Why?
Besides, when errors really have to be collected and analysed then use of
-ErrorVariable
parameter for a particular command is better than use of$Error
which also may contain noise errors.-ErrorVariable
is unlimited.