简体   繁体   中英

What are managed resources and unmanaged resources?

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM