-
Notifications
You must be signed in to change notification settings - Fork 4.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Why doesn't CLR immediately release local objects that leave the scope? #102109
Comments
Tagging subscribers to this area: @JulieLeeMSFT, @jakobbotsch |
Tagging subscribers to this area: @dotnet/gc |
Thank you. Also, do you have more information to share about this?
|
The CLR GC is mark-compact GC. Every time when GC occurs, it scans for alive objects that is reference somewhere. The space occupied by dead objects become "hole" in the memory. It also has the ability to move alive objects to other place to eliminate holes. Holes aren't reusable immediately. The allocator ( |
I have learned about the GC process of the CLR from "CLR via C#." When posing this question, I have considered the issue of "hole". What if we inform the CLR to allocate objects to a dedicated memory region using specific keywords(similar to what was mentioned in #1661)? All objects in this region would be immediately erase on scope ends and not allowed to be promoted. |
It is effectively Since it's just a new concept and fundamentally incompatible with existing types, existing code can't simply benefit from it. |
As a side note: part of the complexity of the analysis is that (looking only at this method), the compiler can't actually know that You need ownership tracking to be able to solve for this type of thing. |
Not sure exactly how Rust does it exactly but can you make use of the "Burrow" concept here? Sort of using that model from Rust to keep track of dangling or valid references and hence deciding when and if to release them by the GC without promoting them to higher Gens. |
In a word, no. Rust's borrow checker imposes restrictions that don't exist in C#, and also requires deep language/compiler support, so it is not really applicable in any useful sense. |
closing since the question looks to be answered |
Why doesn't CLR immediately release local objects that leave the scope?
In this example, object "temp" can be released immediately.
The text was updated successfully, but these errors were encountered: