Automatic release tank
What is? Object, structure
The interview questions 1
- When are temporary variables released
- Automatic release pool principle?
- Whether the auto release pool can be nested
GC garbishi
Are all objects added to automatic release pool management?
1. Clang: CPP source ·__AtAutoReleasePool __autoreleasepool
__objc_autoReleasePoolPush __objc_autoReleasePoolPop struct __AtAutoreleasePool {// Construct __AtAutoreleasePool() {atautoreleasepoolobj = objc_autoreleasePoolPush(); } // Destruct ~__AtAutoreleasePool() {objc_autoreleasePoolPop(atAutoReleasepoolobj); } void * atautoreleasepoolobj; };Copy the code
2. From the assembler callQ, you can also see the push pop call
#import <UIKit/UIKit.h>
#import "AppDelegate.h"
int main(int argc, char * argv[]) {
NSString * appDelegateClassName;
@autoreleasepool {
// Setup code that might create autoreleased objects goes here.
appDelegateClassName = NSStringFromClass([AppDelegate class]);
}
return UIApplicationMain(argc, argv, nil, appDelegateClassName);
}
Copy the code
3. Relationship between Runloop and Autoreleasepool
4. AutoreleasepoolPage source code analysis
4.1. Create a Page
-
Page initialization begin()]
This, sizeof(this) the address of the object, + 56Copy the code
Magic_t structure unit32 4 bytes
MRC NSObject *obj = [[NSObject alloc] autorelease]; _objc_autoreleasePoolPrint();
-
Set the current page to hotPage
-
Sets the current sentinel object
-
Add-page Indicates the ping translation of the memory
(504 (NSObjec object) + 1 (sentry object)) * 8 + 56 bytes (1 page) = 4096