Microsoft says developers should update to .NET Framework 4.6.2 to take advantage of major changes made to the garbage collector. The feature provides automatic memory management and has been improved in the latest version of .NET Framework.
Developers have been able to upgrade to .NET Framework 4.6.2 since the middle of last year. However, many have still not done so. Microsoft points out that upgrading is worth it because the company made a number of key changes.
Chief among them is the garbage collector, which is now more efficient. The tool allows dev's to build new applications without needing to free up new memory. The collection involves allocating objects and reclaim objects not in use.
Previously, the collector would not move an object reported as “pinned survived” if it is next to live data objects. Maoni Stephens, main garbage collector developer at Microsoft, says the company has made changes in version 4.6.2.
“Starting with version 4.6.2, this limitation was lifted so we could compact away the adjacent live objects around pinned objects. In testing, we saw dramatic improvements of ephemeral collection time in scenarios where GC was artificially pinning a lot of objects.”
Garbage collector is now also more adept and managing free space. In older versions, the collector would operate a first fit method when compacting gen1 survivors into gen2 free list. This meant the GC discarded spaces that could not be used. This technique led to wasted spaces in memory.
Garbage Collector Free Space
Dealing with this problem involves a bucketed free list where free space is placed into its respective bucket.
“To improve on this and utilize memory more efficiently, we introduced a bucketed free list where we threaded left over free spaces into their respective bucket. We had to be very careful of the usage in the smallest bucket as there could be many of them. We also worked on a policy of which bucket to try as we didn't want to lengthen the gen1 collection time much by spending more time in searching for a usable free space. We want to stay doing background GCs as much as possible in order to be more efficient at consuming free spaces.”