zoukankan      html  css  js  c++  java
  • Handle unmanaged code in managed c# with the help of using statement

     
    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.
  • 相关阅读:
    积性函数前缀和
    CF1067D Computer Game
    Atcoder Tenka1 Programmer Contest 2019 题解
    Codeforces Round #549 (Div. 1) 题解
    SHOI2019旅游记
    CF871D Paths
    CF1065E Side Transmutations
    停更公告
    博客说明
    SCOI2019酱油记
  • 原文地址:https://www.cnblogs.com/kingangWang/p/2152869.html
Copyright © 2011-2022 走看看