簡體   English   中英

Cordova / PhoneGapp應用程序內存問題

[英]Cordova/PhoneGapp App Memory Issues

我正在使用Cordova開發混合應用程序,該應用程序在除iPad之外的所有設備上都可以正常運行。 該應用程序以地圖為中心,這意味着整個視圖由地圖框地圖占據。 當用戶放大和縮小一點點Xcode會發出內存警告時,多次執行此操作,應用程序將崩潰。 我嘗試使用

[[NSURLCache sharedURLCache] removeAllCachedResponses];

在“已收到內存警告”方法中,該方法似乎已解決了一段時間,但隨着開發的繼續,該問題又重新出現了。

有人看到過這個問題嗎?

您可以嘗試這樣做,看看是否有幫助。

在AppDelegate.m初始化方法中,添加...

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)
}

設置緩存大小之后。

更新:

這是一個示例初始化:

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM