Skip to content

Commit

Permalink
Auto release computed PNG data after caching (#1026)
Browse files Browse the repository at this point in the history
  • Loading branch information
mvasilak authored Nov 18, 2024
1 parent 5de61df commit 5ab1e85
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 17 deletions.
20 changes: 11 additions & 9 deletions Zotero/Controllers/AnnotationPreviewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -306,15 +306,17 @@ extension AnnotationPreviewController {
}

private func cache(image: UIImage, key: String, pdfKey: String, libraryId: LibraryIdentifier, isDark: Bool) {
guard let data = image.pngData() else {
DDLogError("AnnotationPreviewController: can't create data from image")
return
}

do {
try fileStorage.write(data, to: Files.annotationPreview(annotationKey: key, pdfKey: pdfKey, libraryId: libraryId, isDark: isDark), options: .atomicWrite)
} catch let error {
DDLogError("AnnotationPreviewController: can't store preview - \(error)")
autoreleasepool {
guard let data = image.pngData() else {
DDLogError("AnnotationPreviewController: can't create data from image")
return
}

do {
try fileStorage.write(data, to: Files.annotationPreview(annotationKey: key, pdfKey: pdfKey, libraryId: libraryId, isDark: isDark), options: .atomicWrite)
} catch let error {
DDLogError("AnnotationPreviewController: can't store preview - \(error)")
}
}
}
}
18 changes: 10 additions & 8 deletions Zotero/Controllers/PDFThumbnailController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -149,14 +149,16 @@ extension PDFThumbnailController {
}

func cache(image: UIImage, page: UInt, key: String, libraryId: LibraryIdentifier, isDark: Bool) {
guard let data = image.pngData() else {
DDLogError("PdfThumbnailController: can't create data from image")
return
}
do {
try fileStorage.write(data, to: Files.pageThumbnail(pageIndex: page, key: key, libraryId: libraryId, isDark: isDark), options: .atomicWrite)
} catch let error {
DDLogError("PdfThumbnailController: can't store preview - \(error)")
autoreleasepool {
guard let data = image.pngData() else {
DDLogError("PdfThumbnailController: can't create data from image")
return
}
do {
try fileStorage.write(data, to: Files.pageThumbnail(pageIndex: page, key: key, libraryId: libraryId, isDark: isDark), options: .atomicWrite)
} catch let error {
DDLogError("PdfThumbnailController: can't store preview - \(error)")
}
}
}
}
Expand Down

0 comments on commit 5ab1e85

Please sign in to comment.