Cordova / PhoneGap App内存问题

时间:2014-07-23 13:46:11

标签: android ios cordova mapbox

我正在使用Cordova开发混合应用程序,该应用程序适用于除iPad之外的所有设备。该应用程序以地图为中心,这意味着整个视图由地图框图占据。当用户放大甚至稍微放大Xcode时会触发内存警告,多做几次,应用程序就会崩溃。我尝试使用

[[NSURLCache sharedURLCache] removeAllCachedResponses];

中的"确实收到了内存警告"方法,这似乎解决了一段时间的问题,但随着发展的继续,问题已经悄然回归。

还有其他人看过这个问题吗?

1 个答案:

答案 0 :(得分:0)

你可以尝试一下,看看它是否有帮助。

在AppDelegate.m init方法中,添加...

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)
}
设置缓存大小后

更新:

这是一个示例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;
}
相关问题