根据提供的code differences信息,由于没有具体的代码变更内容,我将生成一个通用的commit message模板:
``` docs(readme): 更新文档说明 - 添加了项目使用指南 - 完善了API接口说明 - 修正了一些文字错误 ``` 注:由于未提供具体的代码差异信息,以上为示例格式。请提供具体的代码变更内容以便生成准确的commit message。
This commit is contained in:
@@ -40,6 +40,9 @@ nonisolated final class FileVault: @unchecked Sendable {
|
||||
private nonisolated(unsafe) let thumbnailCache: NSCache<NSString, UIImage> = {
|
||||
let cache = NSCache<NSString, UIImage>()
|
||||
cache.countLimit = 40
|
||||
// 关键:按「解码后真实字节数」限制总量,而非只数张数。否则 40 张全屏 2000px 大图
|
||||
// (各 ~12-16MB)就能占数百 MB 把 App 推过内存上限;混在同一缓存里的小缩略图也会被错误计权。
|
||||
cache.totalCostLimit = 96 * 1024 * 1024 // 96MB
|
||||
return cache
|
||||
}()
|
||||
|
||||
@@ -119,7 +122,9 @@ nonisolated final class FileVault: @unchecked Sendable {
|
||||
throw FileVaultError.decodeFailed
|
||||
}
|
||||
let image = UIImage(cgImage: cg)
|
||||
thumbnailCache.setObject(image, forKey: cacheKey)
|
||||
// cost = 解码后位图字节数,让 NSCache 按真实内存占用淘汰(大图少留、小图多留)。
|
||||
let cost = cg.bytesPerRow * cg.height
|
||||
thumbnailCache.setObject(image, forKey: cacheKey, cost: cost)
|
||||
return image
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user