joydip_kanjilal
Contributor

New features and enhancements in .Net Framework 4.5

opinion
Feb 03, 20154 mins
Software Development

Significant improvements in .Net Framework 4.5

Microsoft .Net Framework has matured a lot over the past few years. New features and enhancements have been introduced aplenty to optimize it and make it fast, secure, more stable, and high performant. In this article I would like to present a bird’s-eye view of the significant improvements in .Net Framework 4.5.x.

The dreaded Out of Memory exceptions

This is a dreaded error and can well become a nightmare for you. Out of Memory exceptions can terminate the flow of control of your application even when you have enough physical memory installed. Are you kidding? No way! Let me explain why this can occur and how this issue has been addressed in .Net Framework 4.5.

Objects created by the managed environment are stored in heap. Over a period of time the heap may become fragmented because of creation and removal of objects. Fragmentation refers to memory holes (free memory) that are scattered. In such a case, you would often observe Out of Memory exceptions if your application uses large amount of memory and because the runtime would be incapable of allocating space when and if needed even if there may be space available.

Sounds weird? Well, the sum of the memory holes may suffice for this request, but as these memory holes are scattered, the runtime cannot use them.

Compaction of Large-Object Heap on demand

The On-Demand Large Object heap compaction has been newly introduced to compact the heap and eliminate heap fragmentation. Compaction implies compacting all these scattered memory holes into one block. This feature is available (on-demand only) from .Net Framework 4.5.1 to mitigate the Out of Memory exception issues. To enable this feature, you need to set the LargeObjectHeapCompactionMode property.

Incidentally, this property can have one of two values: Default and CompactOnce. The former if set would ignore compaction of large object heap during a GC cycle. If you use the latter, the large object heap would be compacted during the next cycle.

Support for ADO.Net Connection Resiliency

You no longer need to write code to implement connection resiliency to establish idle or broken connections. .Net Framework 4.5.1 comes with this feature built in to re-create broken connections to the database.

Improved startup time: Profile optimization

Profile optimization is a feature that has been introduced in .Net Framework 4.5 that minimizes the application startup time. How does this work? A profile is a file that contains the methods the application would need at the time it starts. When the application starts, the Just in Time Compiler (JIT) runs in a background thread and across multiple processors to generate native code from the IL code.

Garbage collection enhancements: Server GC introduced

The managed environment of .Net uses garbage collection to clean up unused or unreferenced objects — objects that are no longer needed. In the earlier versions of .Net Framework, the GC suspended the application threads when it was busy cleaning up the memory. This was a major performance bottleneck as your application had to wait till the GC finished its work.

With .Net Framework 4.5 this is no longer an issue; server GC has been newly introduced to facilitate cleaning of generation-two objects using a background thread and, hence, minimize the load on the main GC thread as the application threads are much less frequently suspended. With .Net Framework 4.5, background garbage collection is supported in both server and workstation GC. Concurrent garbage collection is also supported now; a dedicated thread performs the garbage collection when needed.

Notable improvements in .Net Framework 4.5.2

Microsoft released .Net Framework 4.5.2 recently. The release was announced by Microsoft in the .Net Framework blog. Here’s the link: http://blogs.msdn.com/b/dotnet/archive/2014/05/05/announcing-the-net-framework-4-5-2-release.aspx

Besides improvements in profiling and debugging, there are notable improvements in ASP.Net in .Net Framework 4.5.2. You can now use the HostingEnvironment.QueueBackgroundWorkItem methods to schedule small background tasks asynchronously. To inspect and modify response headers and response codes, you can make use of the HttpResponse.AddOnSendingHeaders and HttpResponseBase.AddOnSendingHeaders methods. You can refer to this MSDN article for further reading: https://msdn.microsoft.com/en-us/library/ms171868%28v=vs.110%29.aspx

What’s coming up next?

Microsoft released a preview version of .Net Framework 4.6 last November. You can download a copy of .Net Framework 4.6 from here: http://www.microsoft.com/en-us/download/details.aspx?id=44928

The software giant also announced that it would revoke its support for .Net Framework versions 4.x through 4.5.1 after January 2016. Read more on this here: http://blogs.msdn.com/b/dotnet/archive/2014/08/07/moving-to-the-net-framework-4-5-2.aspx

joydip_kanjilal
Contributor

Joydip Kanjilal is a Microsoft Most Valuable Professional (MVP) in ASP.NET, as well as a speaker and the author of several books and articles. He received the prestigious MVP award for 2007, 2008, 2009, 2010, 2011, and 2012.

He has more than 20 years of experience in IT, with more than 16 years in Microsoft .Net and related technologies. He has been selected as MSDN Featured Developer of the Fortnight (MSDN) and as Community Credit Winner several times.

He is the author of eight books and more than 500 articles. Many of his articles have been featured at Microsoft’s Official Site on ASP.Net.

He was a speaker at the Spark IT 2010 event and at the Dr. Dobb’s Conference 2014 in Bangalore. He has also worked as a judge for the Jolt Awards at Dr. Dobb's Journal. He is a regular speaker at the SSWUG Virtual Conference, which is held twice each year.

More from this author