Replies: 2 comments 2 replies
-
I would ask this question on stackoverflow, since not that many people read this repository's discussions. |
Beta Was this translation helpful? Give feedback.
0 replies
-
This happens because of how F# compiles top-level statements. Instead of placing local variables into locals, it places them into static fields. Moving all code into function solves the issue open System
let main() =
let mutable obj = new obj()
let weak = new WeakReference(obj)
GC.Collect()
Console.WriteLine("IsAlive: {0} obj!=null is {1}", weak.IsAlive, obj<>null)
obj <- null
GC.Collect()
Console.WriteLine("IsAlive: {0}", weak.IsAlive)
main() There's awesome tool for inspecting compilation result: https://sharplab.io/ |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
This is a piece of C# code:
This is the output you'll see when running the example:
This is the F# code I translated:
The problem is that the reference is still alive after
obj
becomesnull
.Beta Was this translation helpful? Give feedback.
All reactions