Handle unmanaged code in managed c# with the help of using statement
2011-08-25 10:03
561 查看
http://stackoverflow.com/questions/3433197/what-exactly-are-unmanaged-resources Managed resources basically means "managed memory" that is managed by the garbage collector. When you no longer have any references to a managed object (which uses managed memory), the garbage collector will (eventually) release that memory for you. Unmanaged resources are then everything that the garbage collector does not know about. For example: •Open files •Open network connections •Unmanaged memory •In XNA: vertex buffers, index buffers, textures, etc. Normally you want to release those unmanaged resources before you lose all the references you have to the object managing them. You do this by calling Dispose on that object, or (in C#) using the using statement which will handle calling Dispose for you. If you neglect to Dispose of your unmanaged resources correctly, the garbage collector will eventually handle it for you when the object containing that resource is garbage collected (this is "finalization"). But because the garbage collector doesn't know about the unmanaged resources, it can't tell how badly it needs to release them - so it's possible for your program to perform poorly or run out of resources entirely. If you implement a class yourself that handles unmanaged resources, it is up to you to implement Dispose and Finalize correctly. |
相关文章推荐
- the thinker of code complete -- general issues in using variables
- [转]C# and the using Statement in 3 seconds and a bug in Reflector
- Understanding the 'using' statement in C#
- Creating a Web Control with an Expandable Property in the Designer by Using C#.
- Code snippet of the day : Get Chinese Spell in C#
- How to handle exception in managed code and unmanaged code
- Book Contents Reviews Notes Errata Articles Talks Downloads Resources Code Formatter Cover of C# in Depth Order now (3rd edition) Implementing the Singleton Pattern in C#
- managed and unmanaged code in c#
- The Essentials for Using COM in Managed Code
- How to handle exception in managed code and unmanaged code
- A simple Example of using Video Textures in Managed DirectX (C#)
- Test-Driven C# Improve the Design and Flexibility of Your Project with Extreme Programming Techniques
- The basics of using ui-router with AngularJS
- Working with PDF files in C# using PdfBox and IKVM
- Codeforces Beta Round #27 (Codeforces format, Div. 2) E. Number With The Given Amount Of Divisors 反素数
- [软件哲理][转]A piece with a lot of screenshots about the close tab behaviour in Google Chrome
- using sqlite in windows phone 7/successful to deal with the problem in wp to use like select chinese character
- CareerCup Fill the array with product of all numbers except the number in that cell
- Using Weka and Libsvm with C# in Visual Studio
- You cannot access the client's file system using the FileSystemObject in your ASP code