At present, the project uses C # to develop mobile platform projects, so we know the new.
Resource types, generally divided into three categories: stack, managed heap, unmanaged resource
Stack: The memory principle is advanced, and contains the value type and reference type part content.
Value type-" it is the reverse of allocating memory in the order in which resources are disposed, as defined by variables . " Once a value variable is out of scope, the object is removed from the stack .
Heap: Reference type
Reference types are stored in the heap . when new class is used, the object is allocated memory to the managed heap . It can still be used after the method exits for a long time . I use a common example of the class of statements to illustrate the next .
ClassA a=new ClassA ();
This very ordinary sentence can actually be divided into two parts :
First :classa a; declares a classa a, Allocate storage space on the stack for this reference . is not a real object
Second :a=new classa (); a
When the scope is referenced, the reference is removed from the stack , but the data referencing the object is still stored in the managed heap until the program stops , or a GC Delete .
Third: Dispose
If ClassA inherits IDispose, the reason that the program can still access the object after calling the Dispose method . Dispose has no effect on managed resources.
Unmanaged Resources: com/com++ components, ActiveX controls, API functions, WIN32, pointer operations, self-made resource files ... These unmanaged, others are managed.
Summary: C # Unmanaged Resources use the IDispose interface, and managed resources do not need to use the IDispose interface System GC to automatically recycle or use Gc.collect ();
Reference article:
Http://blog.sina.com.cn/s/blog_8abeac5b01019u19.html
http://bbs.csdn.net/topics/270000476
C # Resource Recycling Summary