Live data from Hacker News

.NET GC Internals mini-series

tooslowexception.com

11–20 of 77 posts

Re: .NET GC Internals mini-series

#12

Why .NET still has no interface for serious, custom GCs?

CoreCLR does have the ability to compile the GC as a DLL and then choose different GCs are runtime by loading different DLLs. Search for FEATURE_STANDALONE_GC in the code base.

This feature is enabled in the official builds though.

Re: .NET GC Internals mini-series

#13

Why .NET still has no interface for serious, custom GCs?

CoreCLR does have the ability to compile the GC as a DLL and then choose different GCs are runtime by loading different DLLs. Search for FEATURE_STANDALONE_GC in the code base. This feature is enabled in the official builds though.

You meant "local GC" initiative?

Ain't that relatively young, not so mature and and designed with specific GC design in mind interface?

Re: .NET GC Internals mini-series

#14
Maybe for some readers:

Likely GC abbreviates garbage collection.

Going way back, some programming languages have permitted dynamic storage allocation, that is, a programmer using that language could during execution of the program ask for storage, that is, bytes in main memory, to be allocated, i.e., made available for use. Later the programming could free that storage. E.g., early versions of the programming language Fortran did not offer dynamic storage allocation, but some programmers would implement their own, say, in a Fortran array. Then for pointers to the allocated storage, just use a subscript on the array name. The array might be in storage called COMMON which to the linkage editor was external, thus permitting all parts of the program to use dynamic storage. The programming language PL/I had versions of dynamic storage AUTOMATIC, BASED, and CONTROLLED. The programming language C has storage allocation via the function MALLOC and freeing via FREE.

Well, first cut, intuitively can think of garbage collection (GC) as automated dynamic storage freeing.

In the case of the original post (OP) of this thread, what is going on is, in the .NET languages, C#, Visual Basic (VB), F#, etc., can, e.g., in a function, allocate storage, e.g., with the VB statement ReDim, likely use that storage, have flow control leave that function, leave the storage allocated, and, then, have garbage collection notice automatically when that storage will not be used again and free it, i.e., make it available again for allocation and use. In addition, likely the code for some programming language features need at least dynamic storage and might use GC for freeing.

The broad idea of garbage collection is old, in several programming languages goes back decades. E.g., in PL/I, AUTOMATIC gave automatic storage freeing.

Why should .NET implement garbage collection, that is, why bother? Otherwise sometimes programmers forget to do the garbage collection themselves resulting in allocated storage growing until it is too large. One of the old examples was from cases of handling exceptional conditions; in some cases the code that got control did not have the data to know what storage should be freed.

GC has some challenges:

First, in a rich language, it can be not easy to know what storage should be freed. So, there can be some bugs in GC implementations.

Second, GC takes time, and maybe in some situations, that is, in some programs, takes too much time and results in, say, noticeably slower response time. One place where GC tends to be unwelcome is real time programming where want the software to respond in no more than a few milliseconds to external events that occur at unpredictable times.

One of the main ideas for GC implementation is reference counting where the programming language compiler inserts extra code that, for each instance of appropriate cases of allocated storage, keeps track, say, just a count, of essentially how many variables in the code (for each thread of execution) might use, reference, the storage. Then for such an instance of storage when its reference count reaches zero, free the storage.

Re: .NET GC Internals mini-series

#15
post #5
post #2

How do I know this person really knows about .NET GC internals for me to spend any time watching some videos?

The author is MVP in .NET and author of the book Pro .NET Memory Management.

And that book is as big as War and Peace by Tolstoy and Atlas Shrugged by Rand. So if you want to know the role of an individual memory allocation in the history of the entire application performance, it's a goto thing.

Re: .NET GC Internals mini-series

#16

Earlier quoted context omitted.

CoreCLR does have the ability to compile the GC as a DLL and then choose different GCs are runtime by loading different DLLs. Search for FEATURE_STANDALONE_GC in the code base. This feature is enabled in the official builds though.

You meant "local GC" initiative? Ain't that relatively young, not so mature and and designed with specific GC design in mind interface?

It is. A few key assumptions are based into the runtime, namely that the GC is a generational GC with contiguous regions and that the GC doesn't need a read barrier, among many other things. There's a bunch of assembly in the runtime that embeds some implementation details of the GC in a way that's hard to decouple. The API came about by untangling the GC and the rest of the runtime; it took a lot of work and the resulting API probably isn't what we'd choose if we were building a GC with it in mind from day 1, but the whole scheme of sideloading a GC works pretty well.

Re: .NET GC Internals mini-series

#19
post #6
post #2

How do I know this person really knows about .NET GC internals for me to spend any time watching some videos?

Not that this proves anything, but this author's twitter account is followed by: * David Fowler (ASP.NET Core creator) * Andy Gocke (Lead developer for the CLR) * Jared Parsons (Lead developer for C# Compiler team) * Miguel de Icaza Presumably if he wasn't saying anything worth listening to, they would have unfollowed him by now.

* Maoni Stephens (Works on the .NET Garbage Collector ;)

Re: .NET GC Internals mini-series

#20
post #14

Maybe for some readers: Likely GC abbreviates garbage collection . Going way back, some programming languages have permitted dynamic storage allocation , that is, a programmer using that language could during execution of the program ask for storage , that is, bytes in main memory, to be allocated , i.e., made available for use. Later the programming could free that storage. E.g., early versions of the programming la…

> E.g., early versions of the programming language Fortran did not offer dynamic storage allocation, but some programmers would implement their own, say, in a Fortran array. Then for pointers to the allocated storage, just use a subscript on the array name.

Even today people do the same thing in languages like Java and Rust as workarounds for performance or semantic constraints of the environment while still nominally obeying language semantics. I assume the same phenomenon is true in the C# universe.

When you bring this up many users of those languages are quick to explain why array indices are safer than managing raw memory addresses from outside the language's object model, but let's not go there ;)

Post reply on HN