ASP.NET Core Web API返回类,导致内存泄漏?

发布于 2025-02-10 02:57:30 字数 665 浏览 1 评论 0原文

根据要求,创建了一个ASP.NET Core Web API,以转化为JSON或XML输出的方式。

其中一种典型的返回方法具有诸如

[Microsoft.AspNetCore.Mvc.HttpGet("SomeCommand/{id?}")]
public ActionResult<Response.Command> SomeCommand(int id)
{ 
     // ...
     // Some minimal logic nothing that can cause memory strains

     // A class Response containing sub classes as placeholders for values 
     // Each nested class within has a constructor to set its values
     return new Response.SomeCommand(x)  
}

ASP.NET之类的语法,确实将类正确转换为JSON输出或XML输出没有问题。

但是,它慢慢地使用了越来越多的内存。

有更好的方法吗?

还是迫使垃圾收集者释放这些课程的方法?

还是我不必担心,这是正常的GC(时间很长的时间?)。
(如今,它看起来像是内存泄漏)。

Upon request, an ASP.NET Core Web API was created, in such a way that it translates to json or XML output.

A typical return method in it has a syntax like

[Microsoft.AspNetCore.Mvc.HttpGet("SomeCommand/{id?}")]
public ActionResult<Response.Command> SomeCommand(int id)
{ 
     // ...
     // Some minimal logic nothing that can cause memory strains

     // A class Response containing sub classes as placeholders for values 
     // Each nested class within has a constructor to set its values
     return new Response.SomeCommand(x)  
}

ASP.NET does correctly convert the class to a JSON output or XML output no problems there.

However, it slowly uses more and more memory it seems.

Is there a better way to do this?

Or a way to force the garbage collector to free up those classes?

Or shouldn't I worry about it, it's normal GC takes (a long?) time.
(as now it looks like a memory leak).

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文