1

When should we do memory management and How do we do it for both the types of resources? What is the list of managed and unmanaged resources? Do we really need to worry about memory leaks or not?

sly_Chandan
  • 3,437
  • 12
  • 54
  • 83

1 Answers1

5

Managed resources are those that are fully written in .NET. Though not normally subject to classic memory leaks, one can still leak memory by not dereferencing unused resources (the most common reason is to not un-register event handlers).

Unmanaged resources are those that are generally those that are not pure .NET (and in the same process) - examples are:

  • COM components
  • Database connections/transactions
  • Window handles
  • Filesystem handles
  • Registry handles
  • Network connections
  • etc... etc...

For these, you need to implement the Dispose pattern, correctly and ensure proper disposal when you have finished using them.

Do we really need to worry about memory leaks or not?

Yes, we do need to worry about them, in particular when going outside of .NET.

Community
  • 1
  • 1
Oded
  • 489,969
  • 99
  • 883
  • 1,009