WeakReference broken in .NET5
-
Back to home project after.. a long break! (hence my recent numerous programming posts) :omg: :-D Upgrading my utilities to .NET5, running the tests and then this test broke.... var wo = new WeakReference(new object()); GC.Collect(GC.MaxGeneration, GCCollectionMode.Forced); Assert.False(wo.IsAlive); Wow really? Floored :~:confused: :omg: Work with .NET4.7.2, fails with .NET5 Out of curiosity tried .NET6 (preview). Work again in .NET6, phew.. :rose: :doh: EDIT After some reflection, it's most likely
GC.Collect()
that is broken in .NET5.... little harm done...A new .NET Serializer All in one Menu-Ribbon Bar Taking over the world since 1371!
-
Back to home project after.. a long break! (hence my recent numerous programming posts) :omg: :-D Upgrading my utilities to .NET5, running the tests and then this test broke.... var wo = new WeakReference(new object()); GC.Collect(GC.MaxGeneration, GCCollectionMode.Forced); Assert.False(wo.IsAlive); Wow really? Floored :~:confused: :omg: Work with .NET4.7.2, fails with .NET5 Out of curiosity tried .NET6 (preview). Work again in .NET6, phew.. :rose: :doh: EDIT After some reflection, it's most likely
GC.Collect()
that is broken in .NET5.... little harm done...A new .NET Serializer All in one Menu-Ribbon Bar Taking over the world since 1371!
That was to be expected, they are not called "weak" for nothing :-\
-
That was to be expected, they are not called "weak" for nothing :-\
sick burn! :laugh:
A new .NET Serializer All in one Menu-Ribbon Bar Taking over the world since 1371!
-
Back to home project after.. a long break! (hence my recent numerous programming posts) :omg: :-D Upgrading my utilities to .NET5, running the tests and then this test broke.... var wo = new WeakReference(new object()); GC.Collect(GC.MaxGeneration, GCCollectionMode.Forced); Assert.False(wo.IsAlive); Wow really? Floored :~:confused: :omg: Work with .NET4.7.2, fails with .NET5 Out of curiosity tried .NET6 (preview). Work again in .NET6, phew.. :rose: :doh: EDIT After some reflection, it's most likely
GC.Collect()
that is broken in .NET5.... little harm done...A new .NET Serializer All in one Menu-Ribbon Bar Taking over the world since 1371!
Are you running this in a debug build? If so, try a release build instead. Using LINQPad 6, I can reproduce the behaviour you're setting in a debug build for .NET 5.10; toggling the "o+" switch at the bottom-right to switch to release mode returns the behaviour to normal.
"These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer
-
Are you running this in a debug build? If so, try a release build instead. Using LINQPad 6, I can reproduce the behaviour you're setting in a debug build for .NET 5.10; toggling the "o+" switch at the bottom-right to switch to release mode returns the behaviour to normal.
"These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer
Nice catch
Real programmers use butterflies
-
Are you running this in a debug build? If so, try a release build instead. Using LINQPad 6, I can reproduce the behaviour you're setting in a debug build for .NET 5.10; toggling the "o+" switch at the bottom-right to switch to release mode returns the behaviour to normal.
"These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer
You know what? It indeed work in Release build. First time I see something working significantly differently between build and release in C# for a while I reckon! :O
A new .NET Serializer All in one Menu-Ribbon Bar Taking over the world since 1371!
-
Back to home project after.. a long break! (hence my recent numerous programming posts) :omg: :-D Upgrading my utilities to .NET5, running the tests and then this test broke.... var wo = new WeakReference(new object()); GC.Collect(GC.MaxGeneration, GCCollectionMode.Forced); Assert.False(wo.IsAlive); Wow really? Floored :~:confused: :omg: Work with .NET4.7.2, fails with .NET5 Out of curiosity tried .NET6 (preview). Work again in .NET6, phew.. :rose: :doh: EDIT After some reflection, it's most likely
GC.Collect()
that is broken in .NET5.... little harm done...A new .NET Serializer All in one Menu-Ribbon Bar Taking over the world since 1371!
Super Lloyd wrote:
hence my recent numerous programming posts
You auditioning for the role that Honey...Witch played until recently ? :omg: Go for it :-D
«The mind is not a vessel to be filled but a fire to be kindled» Plutarch
-
Super Lloyd wrote:
hence my recent numerous programming posts
You auditioning for the role that Honey...Witch played until recently ? :omg: Go for it :-D
«The mind is not a vessel to be filled but a fire to be kindled» Plutarch
competition is fierce! :D
A new .NET Serializer All in one Menu-Ribbon Bar Taking over the world since 1371!
-
You know what? It indeed work in Release build. First time I see something working significantly differently between build and release in C# for a while I reckon! :O
A new .NET Serializer All in one Menu-Ribbon Bar Taking over the world since 1371!
For anyone wondering why... this is not because the release build is optimized - it is because extra IL is being injected into the debug build for debugging usability reasons. If you have:
{
var thing1 = new thing1();
// Do things to thing1
var thing2 = new thing2(thing1);
// Do things to thing2
// "Breakpoint here"
}On the breakpoint, you would expect to be able to see thing1. But as the garbage collector no longer see any reference to thing1 it can be collected as soon as the constructor of thing2 is done with it (the constructor does not even have to return). To avoid this the compiler will inject IL to keep the variable "used" until he variable is out of scope seen from C# (or whatever language) - so the closing }. Not sure how much "optimization" is really done in release. Maybe it is really just a "stop bloating" option - at least when I had to look I found release IL is a lot easier to read than debug IL :)
-
Back to home project after.. a long break! (hence my recent numerous programming posts) :omg: :-D Upgrading my utilities to .NET5, running the tests and then this test broke.... var wo = new WeakReference(new object()); GC.Collect(GC.MaxGeneration, GCCollectionMode.Forced); Assert.False(wo.IsAlive); Wow really? Floored :~:confused: :omg: Work with .NET4.7.2, fails with .NET5 Out of curiosity tried .NET6 (preview). Work again in .NET6, phew.. :rose: :doh: EDIT After some reflection, it's most likely
GC.Collect()
that is broken in .NET5.... little harm done...A new .NET Serializer All in one Menu-Ribbon Bar Taking over the world since 1371!
There's so many bugs in .net5 that it's not funny anymore. This is the last one we found that affects us, in something as basic as Directory.GetFiles: .Net Core Directory.GetFiles() operates webDav path · Issue #46723 · dotnet/runtime · GitHub[^]. Still untriaged after eight months. "Move fast, break things" has its place. The basic runtime for a lot of business applications in the world is not that place.
Luca The Price of Freedom is Eternal Vigilance. -- Wing Commander IV En Það Besta Sem Guð Hefur Skapað, Er Nýr Dagur. (But the best thing God has created, is a New Day.) -- Sigur Ròs - Viðrar vel til loftárása
-
There's so many bugs in .net5 that it's not funny anymore. This is the last one we found that affects us, in something as basic as Directory.GetFiles: .Net Core Directory.GetFiles() operates webDav path · Issue #46723 · dotnet/runtime · GitHub[^]. Still untriaged after eight months. "Move fast, break things" has its place. The basic runtime for a lot of business applications in the world is not that place.
Luca The Price of Freedom is Eternal Vigilance. -- Wing Commander IV En Það Besta Sem Guð Hefur Skapað, Er Nýr Dagur. (But the best thing God has created, is a New Day.) -- Sigur Ròs - Viðrar vel til loftárása
Damn....
A new .NET Serializer All in one Menu-Ribbon Bar Taking over the world since 1371!