简体   繁体   中英

Cordova/PhoneGapp App Memory Issues

I am developing a hybrid app using Cordova, the app works great on all devices, except for iPad's. The app is map centric, meaning the whole view is taken up by a map box map. When a user zooms in and out at even a little bit Xcode fires off a memory warning, do this more the a few times and the app will crash. I tried using

[[NSURLCache sharedURLCache] removeAllCachedResponses];

in the "did receive memory warning" method, which seems to fix the problem for a while, but as development has continued the issue has crept back in.

Has anybody else seen this issue?

you can try this to see if it helps any.

In AppDelegate.m init method, add...

if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad) {
    cacheSizeMemory *= 2; (or 1.5, etc. ... test to see what works best)
    cacheSizeDisk *= 2; (or 1.5, etc. ... test to see what works best)
}

after the cache sizes are set.

UPDATE:

Here's a sample init:

- (id)init
{
    NSHTTPCookieStorage* cookieStorage = [NSHTTPCookieStorage sharedHTTPCookieStorage];
    [cookieStorage setCookieAcceptPolicy:NSHTTPCookieAcceptPolicyAlways];

    int cacheSizeMemory = 8 * 1024 * 1024; // 8MB
    int cacheSizeDisk = 32 * 1024 * 1024; // 32MB

    if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad) {
         cacheSizeMemory *= 2;
         cacheSizeDisk *= 2;
    }

#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;
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM