C # Resource Recycling Summary

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.