Created
December 4, 2018 17:21
-
-
Save mikeash/eb5921ee19b41383bbc80a877a536044 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import <Foundation/Foundation.h> | |
#import <objc/runtime.h> | |
class Printer { | |
public: | |
const char *str; | |
~Printer() { puts(str); } | |
}; | |
@interface TestClass: NSObject | |
- init: (const char *)str; | |
@end | |
@implementation TestClass { | |
Printer printer; | |
} | |
- init: (const char *)str { | |
printer.str = str; | |
return self; | |
} | |
@end | |
int main() { | |
[[[TestClass alloc] init: "Normal class destruction"] release]; | |
Class dynamicSubclass = objc_allocateClassPair([TestClass class], "DynamicSubclass", 0); | |
objc_registerClassPair(dynamicSubclass); | |
[[[dynamicSubclass alloc] init: "Dynamic subclass destruction"] release]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment