ios - Web App for iPad memory warning -


i working on web application uses html5, css3, , jquery app. run web files through xcode , use xcode upload "apps" ipads.

recently have been getting memory warning , crash after splash screen spins few seconds.

the apps work fine in xcode simulator, , have noticed seems happen when app has video files (even small ones 800kb).

here console running app on ipad.

how prevent crash?

aug 15 11:50:12 bd-graphics-lab-6-ipad3 bd push button[4020] : multi-tasking -> device: yes, app: yes aug 15 11:50:12 bd-graphics-lab-6-ipad3 kernel[0] : launchd[4020] builtin profile: container (sandbox)

aug 15 11:50:12 bd-graphics-lab-6-ipad3 kernel[0] : launchd[4020] container: /private/var/mobile/applications/997c5f22-c5a6-4a05-96c8-8abea9daac8a (sandbox)

aug 15 11:50:12 bd-graphics-lab-6-ipad3 bd push button[4020] : resetting plugins due page load.

aug 15 11:50:15 bd-graphics-lab-6-ipad3 bd push button[4020] : received memory warning.

aug 15 11:50:17 bd-graphics-lab-6-ipad3 usereventagent[13] : jetsam: kernel termination snapshot being created

aug 15 11:50:17 bd-graphics-lab-6-ipad3 com.apple.launchd1 (uikitapplication:com.bd.push.us.y[0x4721][4020]) : (uikitapplication:com.bd.push.us.y[0x4721]) exited: killed: 9

aug 15 11:50:17 bd-graphics-lab-6-ipad3 backboardd[26] : application 'uikitapplication:com.bd.push.us.y[0x4721]' exited abnormally signal 9: killed: 9

aug 15 11:50:17 bd-graphics-lab-6-ipad3 reportcrash[4021] : libmobilegestalt copysystemversiondictionaryvalue: not lookup releasetype system version dictionary

aug 15 11:50:17 bd-graphics-lab-6-ipad3 reportcrash[4021] : saved crashreport /library/logs/crashreporter/lowmemory-2013-08-15-115017.plist using uid: 0 gid: 0, synthetic_euid: 0 egid: 0

appdelegate.m

@implementation appdelegate  @synthesize window, viewcontroller;  - (id)init {     /** if need app-specific initialization, can here      *  -jm      **/     nshttpcookiestorage* cookiestorage = [nshttpcookiestorage sharedhttpcookiestorage];      [cookiestorage setcookieacceptpolicy:nshttpcookieacceptpolicyalways];      int cachesizememory = 8 * 1024 * 1024; // 8mb     int cachesizedisk = 32 * 1024 * 1024; // 32mb #if __has_feature(objc_arc)         nsurlcache* sharedcache = [[nsurlcache alloc] initwithmemorycapacity:cachesizememory diskcapacity:cachesizedisk diskpath:@"nsurlcache"]; #else         nsurlcache* sharedcache = [[[nsurlcache alloc] initwithmemorycapacity:cachesizememory diskcapacity:cachesizedisk diskpath:@"nsurlcache"] autorelease]; #endif     [nsurlcache setsharedurlcache:sharedcache];      self = [super init];     return self; }  #pragma mark uiapplicationdelegate implementation  /**  * main kick off after app inits, views , settings setup here. (preferred - ios4 , up)  */ - (bool)application:(uiapplication*)application didfinishlaunchingwithoptions:(nsdictionary*)launchoptions {     int cachesizememory = 16*1024*1024; // 16mb     int cachesizedisk = 32*1024*1024; // 32mb     nsurlcache *sharedcache = [[[nsurlcache alloc] initwithmemorycapacity:cachesizememory diskcapacity:cachesizedisk diskpath:@"nsurlcache"] autorelease];     [nsurlcache setsharedurlcache:sharedcache];      cgrect screenbounds = [[uiscreen mainscreen] bounds];  #if __has_feature(objc_arc)         self.window = [[uiwindow alloc] initwithframe:screenbounds]; #else         self.window = [[[uiwindow alloc] initwithframe:screenbounds] autorelease]; #endif     self.window.autoresizessubviews = yes;  #if __has_feature(objc_arc)         self.viewcontroller = [[mainviewcontroller alloc] init]; #else         self.viewcontroller = [[[mainviewcontroller alloc] init] autorelease]; #endif     self.viewcontroller.usesplashscreen = yes;      // set app's start page setting <content src='foo.html' /> tag in config.xml.     // if necessary, uncomment line below override it.     // self.viewcontroller.startpage = @"index.html";      // note: customize view's frame size (which defaults full screen), override     // [self.viewcontroller viewwillappear:] in view controller.      self.window.rootviewcontroller = self.viewcontroller;     [self.window makekeyandvisible];      return yes; }  // happens while running ( in background, or within our own app ) // valid if flush.ca.mbp-info.plist specifies protocol handle - (bool)application:(uiapplication*)application handleopenurl:(nsurl*)url {     if (!url) {         return no;     }      // calls javascript global function 'handleopenurl'     nsstring* jsstring = [nsstring stringwithformat:@"handleopenurl(\"%@\");", url];     [self.viewcontroller.webview stringbyevaluatingjavascriptfromstring:jsstring];      // plugins notification, , handlers called     [[nsnotificationcenter defaultcenter] postnotification:[nsnotification notificationwithname:cdvpluginhandleopenurlnotification object:url]];      return yes; }  // repost localnotification using default nsnotificationcenter multiple plugins may respond - (void)            application:(uiapplication*)application     didreceivelocalnotification:(uilocalnotification*)notification {     // re-post ( broadcast )     [[nsnotificationcenter defaultcenter] postnotificationname:cdvlocalnotification object:notification]; }  - (nsuinteger)application:(uiapplication*)application supportedinterfaceorientationsforwindow:(uiwindow*)window {     // iphone doesn't support upside down default, while ipad does.  override allow orientations always, , let root view controller decide what's allowed (the supported orientations mask gets intersected).     nsuinteger supportedinterfaceorientations = (1 << uiinterfaceorientationportrait) | (1 << uiinterfaceorientationlandscapeleft) | (1 << uiinterfaceorientationlandscaperight) | (1 << uiinterfaceorientationportraitupsidedown);      return supportedinterfaceorientations; }  - (void)applicationdidreceivememorywarning:(uiapplication*)application {     [[nsurlcache sharedurlcache] removeallcachedresponses];     nslog(@"cache cleared"); } 

cdvviewcontroller.m

- (void)didreceivememorywarning {     // iterate through plugin objects, , call haspendingoperation     // if @ least 1 has pending operation, don't call [super didreceivememorywarning]      nsenumerator* enumerator = [self.pluginobjects objectenumerator];     cdvplugin* plugin;      bool dopurge = yes;      while ((plugin = [enumerator nextobject])) {         if (plugin.haspendingoperation) {             nslog(@"plugin '%@' has pending operation, memory purge delayed didreceivememorywarning.", nsstringfromclass([plugin class]));             dopurge = no;         }     }      if (dopurge) {         // releases view if doesn't have superview.         [super didreceivememorywarning];     }      // release cached data, images, etc. aren't in use. }  - (void)viewdidunload {     // release retained subviews of main view.     // e.g. self.myoutlet = nil;      self.webview.delegate = nil;     self.webview = nil;     [cdvuseragentutil releaselock:&_useragentlocktoken]; }  #pragma mark uiwebviewdelegate  /**  when web application loads add stuff dom, user-defined settings settings.plist file, ,  device's data such device id, platform version, etc.  */ - (void)webviewdidstartload:(uiwebview*)thewebview {     nslog(@"resetting plugins due page load.");     [_commandqueue resetrequestid];     [[nsnotificationcenter defaultcenter] postnotification:[nsnotification notificationwithname:cdvpluginresetnotification object:self.webview]]; }  /**  called when webview finishes loading.  stops activity view.  */ - (void)webviewdidfinishload:(uiwebview*)thewebview {     nslog(@"finished load of: %@", thewebview.request.url);     // it's safe release lock if sub-frame that's finished loading.     [cdvuseragentutil releaselock:&_useragentlocktoken];      /*      * hide top activity throbber in battery bar      */     [[uiapplication sharedapplication] setnetworkactivityindicatorvisible:no];      [self processopenurl];      [[nsnotificationcenter defaultcenter] postnotification:[nsnotification notificationwithname:cdvpagedidloadnotification object:self.webview]];  } 

leaks

allocations

enter image description here

i had issue app using phonegap, once implemented fix in app delegate working perfectly. in case since said emptying cache not working, maybe need specify cache size in case use (bool)application code below.

in appdelegate.m

- (bool)application:(uiapplication *)application didfinishlaunchingwithoptions:(nsdictionary *)launchoptions {      int cachesizememory = 16*1024*1024; // 16mb     int cachesizedisk = 32*1024*1024; // 32mb     nsurlcache *sharedcache = [[[nsurlcache alloc] initwithmemorycapacity:cachesizememory diskcapacity:cachesizedisk diskpath:@"nsurlcache"] autorelease];     [nsurlcache setsharedurlcache:sharedcache]; } - (void)applicationdidreceivememorywarning:(uiapplication *)application {     [[nsurlcache sharedurlcache] removeallcachedresponses];     nslog(@"cache cleared"); } 

additionally used in cdvviewcontroller.m clear every 1 second,

- (void)webviewdidfinishload:(uiwebview*)thewebview {   //...       [[nsurlcache sharedurlcache] removeallcachedresponses];         nslog(@"cache cleared");         [nstimer scheduledtimerwithtimeinterval: 1.0                                                       target: self                                                     selector:@selector(ontick:)                                       userinfo: nil repeats: yes];      }      -(void)ontick:(nstimer *)timer {         [[nsurlcache sharedurlcache] removeallcachedresponses];         nslog(@"cache cleared");      } 

Comments

Popular posts from this blog

c# - Send Image in Json : 400 Bad request -

jquery - Fancybox - apply a function to several elements -

An easy way to program an Android keyboard layout app -