C # sister:Memory cleanup is just as troublesome as demolition in life.
Aunt Objective-C:Yes, the split is not split, it occupies space, it should not be split, the program crashes
C # sister:To put it bluntly, the difficulty is not solved. In terms of determination, we can judge whether the memory is useless.
Aunt Objective-C:Yes, it's like demolition in real life. It's not difficult to dig a house. Just let the bulldozer come over. What's hard is to decide which house to dig... The answer is yes, and the answer is wrong.
C # sister:As an advertisement,. NET's garbage collection mechanism is quite good. Accurate judgment ~
Aunt Objective-C:Yes, but you have to pay the price. By checking obsolete objects during runtime, it is like relying on census to determine which houses are useless. It is achieved by regular traversal. After all, performance is affected, in addition, recycling is not as timely as possible.
C # sister:Yes, garbage collection is actually two parts of work. One is "check", the other is "recycle", and the other is "check" to find houses that are not used by anyone, write the word "split" in a large circle on the wall. "Recycling" means to flatten the house marked with "Demolition" and combine the houses still in use to avoid fragmentation. It is also important that the program is suspended during the recycle process.
Aunt Objective-C:What is the international practice of word splitting ?~ The entire process seems very long. How can we ensure the performance?
C # sister:. NET runtime adopts many methods to improve efficiency.
First, it gives priority to the Census of areas with relatively large population flows. Large population flows mean that houses are more likely to be idle. This is mainly optimized by age generation. the space occupied by objects is increased by 1 after each Garbage Collector scan without being cleared. For example, if a house you bought in is found to be in use in the census, the aging will become 1. The Census may no longer check the house, because you have lived for at least two years, and the possibility of migration is lower, the garbage collector will focus on checking the houses new after the last census. Of course, after cleaning up the 0-generation house, there is not enough space, and the garbage collector will check the 1-or even 2-generation house.
Aunt Objective-C:This is discrimination. No wonder I bought a house in Shanghai and didn't have an account. I used to be a 0-generation hacker.
C # sister:No way. Who gives efficiency priority? Who cares about the fairness of our small people ~ The second way to improve the efficiency of the garbage collector is to reduce the number of census tasks, unless the memory occupied by the program exceeds the specification, or the system memory itself is not rich, it is not easy to conduct memory census these bad things. You think the Garbage Collector has been scanning for nothing. They also want to have a rest ~
Aunt Objective-C:There are so many insider information about. NET garbage collection.
C # sister:In a few minutes, don't you think about it. Who is going to demolish this year? Aunt Objective-C, is there no insider in Object Management?
Aunt Objective-C:Well, yes, but it's quite a comparison ~ Because there is room for choice, the previous time I did not say html "target = _ blank> used" Retain, Release "to count the reference quantity of the object to determine whether the object can be recycled, in this way, the professional name is "reference counting technology ". Today, I will continue to talk about the Auto Release Technology ".
C # sister:Auto Release? It sounds very advanced, isn't it similar to my garbage collection.
Aunt Objective-C:Much worse, it is still reference counting in essence. In fact, it is not automated, But it simplifies the logic and code. It's a foreign aid. Let's take the tragic House class as an experiment.
View sourceprint?
01 |
<SPAN style= "FONT-SIZE: 16px" >#import "House.h" |
02 |
// Create an object House class to be deleted first |
04 |
-( void ) dealloc // Objective-C automatically calls this method when the object is destroyed. |
06 |
NSLog (@ "The house has been demolished" ); |
Aunt Objective-C:This unlucky House class only reloads the dealloc method. Have you forgotten it? This method is called during house demolition. Next, execute