Manual Memory Management Techniques

Should we ever enforce to manually remove memory in WPF application?

There are many instances while developing WPF Applications, we come across several scenarios where applications consumes large amount of memory. It mainly happens as we don't spend much time to load appropriate controls and dispose others.

The WPF application as being having smart client, will have large amount of client side data processing. The application also fetches data many times without any pagination, which is ignored at the development.

Because of the poor programming practise, in a situtation where many developer prone to use DataTable, DataSets which are untyped and consumes large amount of memory while the application in production.

Due to improper references to the objects, memory management becomes bigger issue and we land up to a situation where we have to manually release memory.

It is a good practice never force garbage collection manually, in any .NET application. GC is supposed to be smartest than us ( and actually it is smart ). Unfortunately if there is memory leak, even calling forcibly the GC does not help.

The whole purpose of the .NET garbage collector is to manage memory on our behalf. However, in some very rare circumstances, it may be beneficial to programmatically force a garbage collection using GC.Collect(). Specifically:
  • When your application is about to enter into a block of code that you don't want interrupted by a possible garbage collection.
  • When your application has just finished allocating an extremely large number of objects and you wish to remove as much of the acquired memory as soon as possible.



No comments:

Post a Comment