Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
381 views
in Technique[技术] by (71.8m points)

ios - removeFromSuperview then paste new view, it won't release memory

I found PDFView will cause memory leak, so I try another way to show PDF.

I use a scrollView that has a contentView for all the PDF page size.

enter image description here

For example, if one PDF page resolution is 480 x 320, then 5 pages PDF's contentView size is 2400 x 320. And I reuse 3 UIViews (as above image, preload and current pages) for showing PDF pages on contentView, every page size is 480 x 320. If now it shows 1st page, then preload 2nd page; if it shows 2nd page, then preload 1st page and 3rd page.

enter image description here

When scrollview moves to next page, I always load the current shown page and next/last page. So I have to remove page using removeFromSuperview(). Then I load the removed page as new one, and paste it into new position on contentView.

The problem is, removing the page from superview won't release the memory. So a many pages PDF will crash when memory is overload.

So how could I force release memory? I have read those old posts but not find the answer.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...