Memory leaks on Asp.Net Core
See original GitHub issueHello, I am facing memory leaks in MonoTorrent with Asp.Net (Kestrel).
All functionality work perfect but right after first run StartAsync
application begin very quickly take memory, for 10 minutes it occupy in average 20Mb on my machine. It repeated in 100% cases. I tried change some settings but result was same. I checked on different torrent files and on few machines and it also same result. I have prepared a simple test project, you can check it out below. Thanks!
Environment:
MonoTorrent 3.0.0-beta.rev0106 (also checked on 2.0.7)
Windows 10 22H2
Project file
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net7.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="MonoTorrent" Version="3.0.0-beta.rev0106" />
</ItemGroup>
</Project>
Source code
using MonoTorrent;
using MonoTorrent.Client;
using System.Text;
var builder = WebApplication.CreateBuilder ();
var app = builder.Build ();
app.UseExceptionHandler ( "/error" );
app.UseRouting ();
app.MapGet ( "/", TestClass.TestRoute );
app.Run ();
public static class TestClass {
private static ClientEngine m_ClientEngine;
static TestClass () => m_ClientEngine = new ClientEngine ();
public static async Task TestRoute ( HttpContext context ) {
var fileStream = File.OpenRead ( @"path to torrent file" );
var torrent = await Torrent.LoadAsync ( fileStream );
var manager = await m_ClientEngine.AddAsync ( torrent, "Downloads" );
await manager.UpdateSettingsAsync ( new TorrentSettingsBuilder ( manager.Settings ) { MaximumConnections = 40, AllowInitialSeeding = false }.ToSettings () );
await manager.StartAsync ();
await context.Response.Body.WriteAsync ( Encoding.UTF8.GetBytes ( "result" ) );
}
}
Issue Analytics
- State:
- Created 8 months ago
- Comments:6 (4 by maintainers)
Top Results From Across the Web
Memory management and patterns in ASP.NET Core
If the Task Manager memory value increases indefinitely and never flattens out, the app has a memory leak. The following sections demonstrate ...
Read more >Best Practices to Avoid Memory Leaks in ASP.NET
A memory leak happens when an application cannot correctly manage memory allocations and deallocations. Once a memory leak has occurred, the ...
Read more >Asp.Net Core API controller memory leak · Issue #45098
We have identified an issue with Asp.Net core API controllers, specifically related to memory allocation which does not get cleared. Our ...
Read more >Finding that C# memory leak
The fastest way to look into a memory leak is to create a dump file of the process in production. There's no need...
Read more >Fixing a memory leak in .Net Core - A Method to Madness
The memory leak becomes quite obvious : the memory consumption keeps on growing, until it reaches a threshold matching the server's specs. We ......
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Phew!
That’s great - I was getting a bit worried there was something I was missing. These kinds of issues are pretty hard to reproduce independently. I have found some before when people shared profiling data from their own apps though!
Glad to see it’s sorted now!
Hello @alanmcgovern, I make deep investigation and find memory leak in myown source code. In example that I share above I also checked and find it has limit in 200Mb, after it memory not growing with many active torrents in long period of time. Thanks for you check and sorry for interruption. I closed issue.