anita
anita
CC#
Created by anita on 5/8/2024 in #help
Application memory keeps increasing
I have an application whose memory usage keeps increasing. The obvious thought is that I have a memory leak. But it turns out, that if i force GC via GC.Collect(), the memory usage is stable. So I'm not use what to do now? Should I just regularly call GC.Collect()? But this seems a bit off, and I haven't seen another application needing to do this.
27 replies
CC#
Created by anita on 11/3/2023 in #help
✅ Why do my ASP.NET Core Requests not run in parallel?
var builder = WebApplication.CreateBuilder(args);
var app = builder.Build();
app.MapGet("/slow", async () => await Task.Delay(5000));
app.Run();
var builder = WebApplication.CreateBuilder(args);
var app = builder.Build();
app.MapGet("/slow", async () => await Task.Delay(5000));
app.Run();
If I call the /slow enpoints multiple times in short succession, I can see that they are not processed in parallel. I can see that because they take longer than 5 seconds (except first one). This is confusing to me, as I would expect them to await the delay in parallel. Can someone explain why this is?
19 replies
CC#
Created by anita on 11/19/2022 in #help
✅ I don't understand GC
The output of this code is True, False. Why? Both instances of Class1 don't have any reference pointing to them. But only one of them is garbage collected. What am I missing?
var we = Method1();
Console.WriteLine(IsGcCollected(we));

Method2();

[MethodImpl(MethodImplOptions.NoInlining)]
WeakReference Method1()
{
var c = new Class1(1);
return new WeakReference(c);
}

[MethodImpl(MethodImplOptions.NoInlining)]
void Method2()
{
var c = new Class1(1);
var w = new WeakReference(c);
c = null;
Console.Write(IsGcCollected(w));
}

bool IsGcCollected(WeakReference w)
{
for (var i = 0; w.IsAlive && i < 10; i++)
{
GC.Collect();
GC.WaitForPendingFinalizers();
}

return !w.IsAlive;
}

class Class1{
public Class1(int propterty1)
{
Propterty1 = propterty1;
}

public int Propterty1 { get; set; }
}

var we = Method1();
Console.WriteLine(IsGcCollected(we));

Method2();

[MethodImpl(MethodImplOptions.NoInlining)]
WeakReference Method1()
{
var c = new Class1(1);
return new WeakReference(c);
}

[MethodImpl(MethodImplOptions.NoInlining)]
void Method2()
{
var c = new Class1(1);
var w = new WeakReference(c);
c = null;
Console.Write(IsGcCollected(w));
}

bool IsGcCollected(WeakReference w)
{
for (var i = 0; w.IsAlive && i < 10; i++)
{
GC.Collect();
GC.WaitForPendingFinalizers();
}

return !w.IsAlive;
}

class Class1{
public Class1(int propterty1)
{
Propterty1 = propterty1;
}

public int Propterty1 { get; set; }
}

5 replies
CC#
Created by anita on 11/13/2022 in #help
❔ The package ID is reserved - when it is not
I tried publishing my first nuget package to nuget.org. But I get the error "The package ID is reserved". I have searched on nuget.org and I cant find any package that has the same name. The package has the id "Joa.API". I have seen that there is a thing called "Package ID Prefix Reservation". But I also cant find any packages that start with Joa. So my question is, what reasons could there be for this error occurs to occur?
2 replies