简体   繁体   中英

iOS11 PDFView Memeory Leak

I use PDFView to display PDFs. If I scroll quickly I get memory leaks.

let pdfView = PDFView.init(frame: CGRect.zero)
self.view.insertSubview(pdfView, belowSubview: bottomBar)
pdfView.snp.makeConstraints { (make) in
    make.top.equalTo(topBar.snp.bottom).offset(8)
    make.left.equalTo(8)
    make.right.equalTo(-8)
    make.bottom.equalTo(-54)
}
let url = Bundle.main.url(forResource: "swift", withExtension: "pdf")!
let doc = PDFDocument.init(url: url)
pdfView.document = doc
if let page = doc?.page(at: 0) {
    let rect = page.bounds(for: .mediaBox)
    let scale = (UIScreen.width - 16) / rect.width
    pdfView.minScaleFactor = scale
    pdfView.maxScaleFactor = scale
    pdfView.scaleFactor = scale
    pdfView.displaysPageBreaks = true
    pdfView.pageBreakMargins = UIEdgeInsets.init(top: 0, left: 0, bottom: 8/scale, right: 0)
    pdfView.layoutDocumentView()
}

View Memory Graph Image

在此处输入图片说明

Can you try to display your PDF in a WebView instead ?

Something like this :

let url = yourLocalURL
webView.loadRequest(URLRequest(url: URL(string: url)!))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM