Created
May 19, 2012 17:52
-
-
Save 0xced/2731698 to your computer and use it in GitHub Desktop.
Solves the problem of .cxx_destruct methods not being called when zombies are enabled
This file contains hidden or 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 <objc/runtime.h> | |
@implementation NSObject (ARCZombie) | |
+ (void) load | |
{ | |
const char *NSZombieEnabled = getenv("NSZombieEnabled"); | |
if (NSZombieEnabled && tolower(NSZombieEnabled[0]) == 'y') | |
{ | |
Method dealloc = class_getInstanceMethod(self, @selector(dealloc)); | |
Method arczombie_dealloc = class_getInstanceMethod(self, @selector(arczombie_dealloc)); | |
method_exchangeImplementations(dealloc, arczombie_dealloc); | |
} | |
} | |
- (void) arczombie_dealloc | |
{ | |
Class aliveClass = object_getClass(self); | |
[self arczombie_dealloc]; | |
Class zombieClass = object_getClass(self); | |
object_setClass(self, aliveClass); | |
objc_destructInstance(self); | |
object_setClass(self, zombieClass); | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This bug should be fixed in iOS 6 and OS X 10.8 according to Technical Q&A QA1758.