在我们的一项 ASP.NET Core 服务中,我们注意到每次请求后内存都在增加。它在 2 天内达到约 2GB。
我试图调查这个问题,我发现这个问题(可能)是垃圾收集器没有被触发。
为了使调查更容易,我尝试使用一个简单的 Web API 应用程序(Dotnet Core 2.1 版,在调试和发布/自包含和 IIS Express 中从 Visual Studio 模板创建)来了解情况
这个全新的应用程序有同样的问题。每个请求的内存都会增加,并且永远不会被释放,如下图所示。
在系统内存不足的情况下,GC 会被触发,但内存永远不会下降。这是正常的吗?
因为这很奇怪,所以我在 Framework 4.6 上用一个简单的 ASP.NET 做了同样的测试。内存被释放。
这很奇怪,不能接受。谁能向我解释一下 ASP.NET Core 内存发生了什么?
编辑:
根据要求,这是我的代码,一个从 Visual Studio 生成的非常基本的 ASP.NET Core:
public class Startup
{
public Startup(IConfiguration configuration)
{
Configuration = configuration;
}
public IConfiguration Configuration { get; }
// This method gets called by the runtime. Use this method to add services to the …Run Code Online (Sandbox Code Playgroud) 第一次在这里提问。请善待:)
我试图以并行方式递归地获取所有目录,希望减少遍历驱动器所需的时间。下面是我尝试过的代码。本质上我想要做的是输入一个文件夹并对其子文件夹及其子文件夹等并行执行相同的操作,但该函数在并行块内无法识别
function New-RecursiveDirectoryList {
[CmdletBinding()]
param (
# Specifies a path to one or more locations.
[Parameter(Mandatory = $true,
Position = 0,
ValueFromPipeline = $true,
ValueFromPipelineByPropertyName = $true,
HelpMessage = 'Path to one or more locations.')]
[Alias('PSPath')]
[ValidateNotNullOrEmpty()]
[string[]]
$Path
)
process {
foreach ($aPath in $Path) {
Get-Item $aPath
Get-ChildItem -Path $aPath -Directory |
# Recursively call itself in Parallel block not working
# Getting error "The term 'New-RecursiveDirectoryList' is not recognized as a name of a cmdlet" …Run Code Online (Sandbox Code Playgroud) 我需要一些关于如何使用 Main 方法中的一些示例值初始化以下对象以执行某些操作的帮助。
由于我是 C# 新手,请指导我从哪里可以获得此信息
class MobOwner
{
public string Name { get; set; }
public List<string> Mobiles { get; set; }
}
Run Code Online (Sandbox Code Playgroud) 这是我的脚本,运行良好。
$include = @(
'File.M*'
'ABC.M*'
'XYZ.M*'
)
Run Code Online (Sandbox Code Playgroud)
最后有.M*。无论如何,我可以简单地使用.M*支架外的公共点吗?像这样的东西:
$include= @((
"File"
"ABC"
"XYZ"
)+.M*)
Run Code Online (Sandbox Code Playgroud)