Find causes for unmanaged memory leaks within managed code.


Unmanaged memory is often leaked when you forget to write code to deallocate it. However, this can also happen when references are retained to the managed object which is responsible for deallocating it.

In other words, unmanaged memory can be held on to by managed memory. So even when it looks like you have an unmanaged problem, it can instead be a problem with your managed code. Code profilers like JetBrains dot Memory Profiler, ANTS Memory Profiler can help demonstrate these kinds of leaks by showing you the chains of references holding unmanaged data in memory. 

It is a good idea to dispose the object when you no longer need it, especially if the object uses unmanaged resources. Not disposing unmanaged resources will lead to memory leaks.

In below image, I found some unmanaged memory utilization in my managed code. 




This unmanaged memory utilization in managed code is one example. Each time when user log into my application, this Native Code consumes unmanaged memory which become in MB and in couple of weeks become in GBs.

We looked into the managed code and dispose the objects properly and re-write some code to handle this issue.

Comments

Popular posts from this blog

Data Bound Controls in ASP.Net - Part 4 (FormView and DetailsView controls)

ASP.net: HttpHandlers

The Clickjacking attack and X-Frame-Options