Skip to content
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

Please make weak reference a language feature instead of class #4154

Closed
ygc369 opened this issue Apr 21, 2015 · 2 comments
Closed

Please make weak reference a language feature instead of class #4154

ygc369 opened this issue Apr 21, 2015 · 2 comments

Comments

@ygc369
Copy link

ygc369 commented Apr 21, 2015

Current weak reference is class, when we use it, we must alloc slots from short or long weak reference table. Thus we can't use too many weak references. But I think this is not necessary. When GC happens, CLR can update strong references of living objects after compaction, why not update weak references of freed objects to be null at the same time? So weak reference can be a language feature instead of class, for example, use keyword "weakref" to specify a variable to store weak reference of an object.
Example:
Class A
{
weakref int[] a;
weakref object b;
};

@kangaroo
Copy link
Contributor

@ygc369 Language features like this should be made against the roslyn repo. There may be some runtime support needed here, but that work would coincide with a language spec update.

@jkotas
Copy link
Member

jkotas commented Apr 21, 2015

System.Runtime.InteropServices.GCHandle is unsafe low-level weak reference type that avoids the problem with extra allocation that you are pointing out.

The feature request to create a first class syntax for it should go into Roslyn repo as @kangaroo pointed out. There is actually a very similar one already - focused on event handlers: dotnet/roslyn#101

@jkotas jkotas closed this as completed Apr 21, 2015
@msftgits msftgits transferred this issue from dotnet/coreclr Jan 30, 2020
@ghost ghost locked as resolved and limited conversation to collaborators Jan 6, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants