Skip to content

Instantly share code, notes, and snippets.

@mikeash
Created December 4, 2018 17:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mikeash/eb5921ee19b41383bbc80a877a536044 to your computer and use it in GitHub Desktop.
Save mikeash/eb5921ee19b41383bbc80a877a536044 to your computer and use it in GitHub Desktop.
#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