Adding Safe Manual Memory Management to .NET
How do we perform memory management for memory-hungry applications that run on machines with dozens or hundreds of gigabytes of memory? While garbage collection ensures memory safety and greatly improves programmer productivity, it can also introduce substantial costs particularly with very large heaps. Manual memory management on the other hand can often deliver better performance but is typically unsafe and can lead to system crashes or vulnerabilities. In this talk I will present our long-term efforts to introduce safe manual memory management alongside GC in the .NET runtime, in order to get the best of both worlds. I will describe the advantages and challenges of working with an existing production type system and runtime and its garbage collector. I will show how lightweight static and dynamic mechanisms can be combined in order to ensure memory safety in the presence of aliasing and concurrency without compromising backwards compatibility, and without introducing existing .NET code performance regressions. I will finally discuss several points in the design space that we considered (and implemented) in the course of this project, that – despite being scientifically novel – were found to be less fit for the constrained context of .NET.