Created
February 25, 2014 04:00
-
-
Save tosik/9202444 to your computer and use it in GitHub Desktop.
Adobe AIR for iOS の Low memory warning による GC 大量発生を無視する方法 ref: http://qiita.com/tosik/items/9f9b474f03777626a42d
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
| // AirLowMemoryWarningSuppressor.h | |
| #import <UIKit/UIKit.h> | |
| #import "FlashRuntimeExtensions.h" | |
| @interface AirLowMemoryWarningSuppressor : NSObject <UIApplicationDelegate> | |
| @end | |
| // AirLowMemoryWarningSuppressor.m | |
| @implementation AirLowMemoryWarningSuppressor | |
| - (void)applicationDidReceiveMemoryWarning:(UIApplication *)application {} | |
| @end | |
| void AirLowMemoryWarningSuppressor_didReceiveMemoryWarning(id self, SEL _cmd, UIApplication* application) | |
| { | |
| NSLog(@"application did receive memory warning."); | |
| } | |
| void AirLowMemoryWarningSuppressor_injectDelegates(id delegate) | |
| { | |
| Class objectClass = object_getClass(delegate); | |
| NSString *newClassName = [NSString stringWithFormat:@"CustomLowMemory_%@", NSStringFromClass(objectClass)]; | |
| Class modDelegate = NSClassFromString(newClassName); | |
| if (modDelegate == nil) { | |
| modDelegate = objc_allocateClassPair(objectClass, [newClassName UTF8String], 0); | |
| SEL selectorToOverride = @selector(applicationDidReceiveMemoryWarning:); | |
| Method m = class_getInstanceMethod(objectClass, selectorToOverride); | |
| class_addMethod(modDelegate, selectorToOverride, (IMP)AirLowMemoryWarningSuppressor_didReceiveMemoryWarning, method_getTypeEncoding(m)); | |
| objc_registerClassPair(modDelegate); | |
| } | |
| object_setClass(delegate, modDelegate); | |
| } | |
| void AirLowMemoryWarningSuppressor_initializeContext(void* extData, const uint8_t* ctxType, FREContext ctx, uint32_t* numFunctionsToTest, const FRENamedFunction** functionsToSet) | |
| { | |
| AirLowMemoryWarningSuppressor_injectDelegates([[UIApplication sharedApplication] delegate]); | |
| *numFunctionsToTest = 0; | |
| } | |
| void AirLowMemoryWarningSuppressor_finalizeContext(FREContext ctx) { } | |
| void LowMemoryInitializeExtension(void** extDataToSet, FREContextInitializer* ctxInitializerToSet, FREContextFinalizer* ctxFinalizerToSet) | |
| { | |
| *extDataToSet = NULL; | |
| *ctxInitializerToSet = &AirLowMemoryWarningSuppressor_initializeContext; | |
| *ctxFinalizerToSet = &AirLowMemoryWarningSuppressor_finalizeContext; | |
| } | |
| void LowMemoryFinalizeExtension(void *extData) { } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment