当前位置:网站首页>Autoreleasepool problem summary
Autoreleasepool problem summary
2022-07-28 05:06:00 【Lu_ Ca】
AutoreleasepoolPage
call autorelease The object eventually passes through AutoreleasepoolPage Objects to manage .AutoreleasepoolPage The structure of the object is as follows
Next: Point to the latest autorelease The next position of the object , That is, the first available location .
thread: Current thread .
parent: Point to parent node , Of the first node parent yes nil.
Child: Point to the child node , Of the last node child Point to nil.
Depth: Expressing depth .
magic: Used to verify AutoreleasepoolPage Whether the structure is complete .
Hiwat: Upper limit of data container
Every autoreleasepoolpage Object occupancy 4096 Byte memory , In addition to storing internal member variables , The rest is stored autorelease Address of the object .autoreleasepoolpage The object is through Double linked list Connected together in the form of .
push and pop Method
When an object calls [object autorelease] Function will add the object to autoreleasepool in , That is to say, it will go on push operation .
push operation , Will be called to autoreleaseFast function . This is its initialization function . By calling hotpage() function , Judge that there are three situations :
1、 If hotpage There is , And the capacity is not full , Then call directly add Function to add an object .
2、 If hotpage There is , But it's full , call autoreleaseFullPage function , And initialize a AutoreleasePage Marked as hotpage.
3、 If hotpage non-existent , call autoreleaseNoPage function , Create a AutoreleasePage Marked as hotpage, Add sentinel object .
Autoreleasepool Of pop The operation is mainly
1、 Get the location through the sentinel object autoreleasepoolpage
2、 call page->releaseUntil(stop) function , To the top of the stack stop Objects call objc_release() Operation reference count -1
3、 Last call child Of kill Method .
autoreleasepool Creation and release time of
establish
App After starting , Main thread runloop Two will be added in observer, The first is surveillance loop Of entry event , Within the callback event autoreleaspoolpush Create an automatic release pool . And set this observer Of order The highest priority ( Negative 2 Of 32 Power -1), Ensure that the automatic release pool is created before other callbacks .
Release
the second observer Monitoring is to prepare for hibernation and about to exit runloop, It calls autoreleasepoolpop Release the automatic release pool , Its observer Of order Set the lowest priority (2 Of 32 Power -1), It ensures that the automatic release pool is released after other callbacks . It prevents the automatic release pool from releasing objects prematurely and causing crashes .
Object release timing
mrc Next
Manual call autorelease Method , The release timing is not determined by the scope of the object , But according to runloop Different states of , When runloop The system will be cleaned up at the end autorelease Objects to be processed . and runloop The end is not fixed duration.
arc Next
Local objects are destroyed after they are out of scope , When the system is out of scope , Call it automatically release Method .
autoreleasepool Use scenarios
Official documents indicate that there are three scenarios :
1、 When writing a command line program , No, UI Framework procedures . because autorelease The mechanism is based on UI framework, So if it's not based on UI framework Your program needs to manage the life cycle of the object itself .
2、 Write a cycle , It contains a large number of temporarily created objects . because autorelease The trigger time is next runloop When , So if there are a lot of autorelease object , Then next time runloop There is no chance to be released before coming back , Will cause memory explosion , May cause crash problems .
3、 Create your own thread .
What objects will be added to Autoreleasepool in
1、 Use alloc、copy、new Etc , System management object memory .
2、 Use __weak Decorated object , To ensure that references are not discarded , Will register to Autoreleasepool in .
3、id Pointer to or pointer to an object , It will be registered to Autoreleasepool in .
边栏推荐
- CPU and memory usage are too high. How to modify RTSP round robin detection parameters to reduce server consumption?
- When initializing with pyqt5, super() and_ init _ () problems faced by the coordinated use of functions, as well as the corresponding learning and solutions
- Interview fraud: there are companies that make money from interviews
- Angr(十一)——官方文档(Part2)
- Euler road / Euler circuit
- Applet import project
- Reading notes of SMT practical guide 1
- I interviewed a 38 year old programmer and refused to work overtime
- Improve the core quality of steam education among students
- Know etcd
猜你喜欢

【ARXIV2204】Vision Transformers for Single Image Dehazing

CPU and memory usage are too high. How to modify RTSP round robin detection parameters to reduce server consumption?

Redux basic syntax

Inspire domestic students to learn robot programming education for children

Research on the design of robot education in stem course

RT_ Use of thread message queue

【ARXIV2203】SepViT: Separable Vision Transformer

Method of converting UI file to py file

RT_ Use of thread mailbox

Melt cloud x chat, create a "stress free social" habitat with sound
随机推荐
【CVPR2022】Multi-Scale High-Resolution Vision Transformer for Semantic Segmentation
阿里怎么用DDD来拆分微服务?
(2.4) [service Trojan -slimftp] introduction and use
【内功心法】——函数栈帧的创建和销毁(C实现)
FPGA:使用PWM波控制LED亮度
FreeRTOS personal notes - task notification
Take out system file upload
Clickhouse填坑记2:Join条件不支持大于、小于等非等式判断
Real intelligence has been certified by two of the world's top market research institutions and has entered the global camp of excellence
C语言ATM自动取款机系统项目的设计与开发
Flink mind map
HDU 1522 marriage is stable
Histogram of pyplot module of Matplotlib (hist(): basic parameter, return value)
Handling of web page image loading errors
Installing MySQL under Linux
Evolution of ape counseling technology: helping teaching and learning conceive future schools
Simulink automatically generates STM32 code details
[paper notes] - low illumination image enhancement - zeroshot - rrdnet Network - 2020-icme
【CPU占用高】software_reporter_tool.exe
After a year of unemployment, I learned to do cross-border e-commerce and earned 520000. Only then did I know that going to work really delayed making money!