Atitit. The principle and design of time base GC garbage resource collection
. MRC (mannulreference counting manual retain/release/autorelease statement 1
2 . Automatic garbage collection (GC) 1
3 . ARC ARC is between automatic garbage collection (GC) and manual memory management. 1
3 . 1. from the most basic ways of running garbage collection algorithms, it can be divided into three types: 1. Reference count (reference counting): 1
3 . 2. Mark-Sweep (Mark-sweep) 2
3 . 3. 3. Node replication (copying). Sub-generational 2
3 . 4. Attilax Time Base GC 3
4 . Second, How the GC works 3
5 . How to associate ----Wrap file,network socket 4
6 . Reference 4
1.MRC(mannulreference countingManualretain/release/autorelease Statements
2.Automatic garbage collection (GC)
3.ARCARC is between automatic garbage collection (GC) and manual memory management.
ARCbetween automatic garbage collection(GC)and manual memory management. It's like garbage collection,ARClet programmers no longer need to writeRetain/release/autoreleasestatement. But it's different from garbage collection,ARCcannot processRetaincycles. In theARCif two objects are strongly referenced to each other (Strong References) will cause them to never be freed, even without any object referencing them. Therefore, whileARCcan eliminate most of the programmer's memory management problems, but still want the programmer to avoidRetaincyclesor manually break the object between theretainloops.
author:: Nickname:Old Wow's claws( Full Name::AttilaxAkbar Al Rapanui Attilaksachanui) Kanji Name:Ayron, email:[email protected]
Reprint please indicate source: http://www.cnblogs.com/attilax/
3.1. from the most basic ways of running garbage collection algorithms, it can be divided into three types:
1. Reference count (reference counting):
Span style= "font-family: Song body; font-size:12pt; " The basic idea is to add a counter to each object and record the number of references to that object. Each time a new reference is directed to the object, the counter adds one, and each time a pointer to the object reference is placed or points to another object, the counter is reduced by one. When the counter changes to 0 , the object is automatically deleted.
Examples of reference counts that are still mostly used are the std::shared_ptr in Apple's arc,c++ new standard.
3.2. Mark-Sweep (Mark-sweep)
。
The basic idea is to allocate on demand, wait until there is no free memory from the register and the reference on the stack to start, traverse the object as a node, the reference as the edge of the graph, all the objects can be accessed to mark, and then sweep the memory space, all unmarked objects released.
Tag-sweep There is no problem that cannot handle circular references, nor does it affect the execution performance of normal programs without triggering the GC. However, the problem is that when memory exhaustion triggers a GC, the normal program needs to be interrupted for a period of time to clean up the memory, which can be very long when there are many large objects in memory.
There are many examples of the use or partial use of Mark-sweep, which are not listed.
3.3.3. Node replication (copying). Sub-generational
The basic idea is to divide the entire memory space into a and B. The memory of all objects is allocated in a, and when a is full, the same goes from the register and the reference on the stack, traversing the graph with objects as nodes, referencing as edges, copying all accessible objects to B, and then swapping the roles of A and B.
With respect to tag-sweep, the main disadvantage of node replication is that half of the space is idle, and the other obscure drawback is that it uses memory in a way that has potential conflicts with existing memory paging and Cache swap-out mechanisms. But it has a big advantage: all objects are always tightly aligned in memory, so the task of allocating memory is very simple, just move a pointer. For environments with frequent memory allocations, the performance benefits are significant. In addition, because there is no need to clean the entire memory space, so if there are few surviving objects in memory and many garbage objects (some languages have this tendency), triggering the GC caused by the interruption will be less than the mark-sweep.
According to a statistical conclusion, if a memory object is found not to be garbage in a certain mark process, it is less likely to become garbage in a short period of time. Generational collection sets the memory objects that are not marked as garbage objects in the garbage collection process to another area-an old area where the memory objects in this area are older. Because memory objects in older areas are less likely to become garbage in the short term, the frequency of garbage collection in these areas can be reduced, relative to high-frequency garbage collection for objects in young areas. This can improve the overall performance of garbage collection.
= = = Basic algorithm introduction complete the split line = =
Each of the above three basic algorithms have advantages and disadvantages, but also have many improved programs. At present, the most successful project in engineering practice should be counted as generational garbage collection. The basic idea is this: there are a lot of temporary objects in the program, the allocation will soon be released, and if an object is allocated for a long period of time is not recycled, it is very likely that its life cycle is very long, it would be useless to try to collect it. So the memory can be consciously according to "Object age" into a number of blocks, it may be remembered as special consideration should (XD), all the distribution in the green generation, green generation plug only to the green generation to do GC, and then the surviving objects moved to the middle generation, until the Qing Dynasty are stuffed, and then the surviving objects moved to the old generation-- This is just an example of the idea, the practice of the sub-generation garbage collection algorithm of a variety of schemes, and often used at the same time more than one basic algorithm (such as the Green Alternative node replication, the old replacement tag sweep what).
3.4.Attilax Time Base GC
4.Second, How the GC works
the GC workflow is mainly divided into the following steps:
1, Mark (Mark)
2. Planning (Plan )
3. Cleaning (Sweep)
4. Reference Update (relocate)
5. Compression (compact)
5.How to associate ----Wrap file,network socket
I want to improve this, which means that all GC -related data is lumped together, and the entire collection process will not touch the memory of the user's data block other than the final release of memory that is no longer in use.
gc C 
On the user's call stack, the temporarily allocated memory at each call level is naturally hooked up to the current level of the stack mount point, and once the call returns, all temporary memory blocks at the current level should be disconnected from the root. Of course, if a memory block appears as a return value, it needs to be preserved. In C , we need to do a guardianship of each function's entrance and exit to ensure that the GC works correctly. ( in the case of C + + , it is a little easier to set a guard object at the function entry point ) Because this monitoring process is very frequent and the optimization of it is focused on the work.
6.Reference
What garbage collection algorithms are used in the implementation of various programming languages? What are the advantages and disadvantages of these algorithms? -GC garbage Collection (computer science) - know . html
Garbage collection mechanism GC knowledge sum up and discuss how to use good gc-jeffwong- Blog Park . html ()imp
three basic ways of garbage collection (GC) - blog - bó lè online . html
Atitit. time base gc Garbage Resources collection principles and design