Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Offline mode 快速滑動會引起 crash #6

Closed
yaqinking opened this issue May 15, 2016 · 0 comments
Closed

Offline mode 快速滑動會引起 crash #6

yaqinking opened this issue May 15, 2016 · 0 comments

Comments

@yaqinking
Copy link
Owner

設置:

  • Preview Image Type: Predownload pictures
  • Download Image Type: Sample
  • Preload next page image: On
  • Offline mode: On

上下來回滑動速度很快的時候 100% 引起 crash。

大概原因能猜到是因爲內存佔用過高。


解決方法是:

給 SDWebImage 設定最大內存緩存佔用數值

// 在 viewDidLoad: 里
[[SDImageCache sharedImageCache] setMaxMemoryCost:[self deviceMaxMemoryCost]];

- (NSInteger)deviceMaxMemoryCost {
    unsigned long long physicalMemory = [NSProcessInfo processInfo].physicalMemory;
    NSInteger allowedMaxMemory = physicalMemory*0.5/4;
    return allowedMaxMemory;
}

由於 SDWebImage 使用 NSCache 作爲緩存,而 NSCache 佔用的內存並不會在 Xcode Debug Seesion Tab 的 Memory Usage 里顯示出來,需要使用在 Instruments 里才能看到是 CG raster data 在佔用大量的內存,設定好上面的值讓它在 iOS 系統單個 app 的最大 limit 值內之後,解決。上面設置爲設備最大內存的一半

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant