久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

將 uiimage 設置為 nil 不會使用 ARC 釋放內存

Setting uiimage to nil doesn#39;t release memory with ARC(將 uiimage 設置為 nil 不會使用 ARC 釋放內存)
本文介紹了將 uiimage 設置為 nil 不會使用 ARC 釋放內存的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我有一個滾動視圖,可以在滾動頁面時顯示不同的圖像,例如 PhotoScroller.我正在使用ARC.當有人滾動到另一個頁面時,我將當前未顯示的 UIImageView 的圖像屬性設置為 nil,因為(試圖)避免內存崩潰,這種情況仍在發生.然后當用戶滾動到一個新頁面時,該頁面的圖像被設置為 UIImageView 的圖像屬性,以及它之前和之后的頁面(為了流暢查看).頁面的 UIImage 都保存在一個數組中.然而,當我滾動頁面時,內存使用量一直在上升,好像將 UIImageView 的 image 屬性設置為 nil 并沒有從內存中釋放它.我使用 initWithContentsOfFile 來初始化我的 UIImages.我也嘗試使用 imageNamedimageWithContentsOfFile ,但沒有成功.這是我的滾動視圖代碼:

I have a scrollview that shows different images as it's scrolled through the pages, like PhotoScroller. I'm using ARC. When someone scrolls to another page, I set the image property of the UIImageView not being currently show to nil, as (attempting) to avoid memory crashes, which are still happening. Then when the user scrolls to a new page, the image for that page is set as the UIImageView's image property, as well as the page before and after it (for smooth viewing). The UIImage's for the pages are all held in an array. Yet as I scroll through the pages, memory usage keeps going up, as if setting the UIImageView's image property to nil isn't releasing it from memory. I use initWithContentsOfFile to initialize my UIImages. I tried with imageNamed and imageWithContentsOfFile too, with no luck. Here's my scrollview code:

<代碼>- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView{
int indexShown = self.scrollView.bounds.origin.x/kScrollObjWidth;

for(NSNumber *index in indexesToRemove)
{
    UIImageView *imgViewToRemove = [[self.scrollView subviews] objectAtIndex:[index intValue]];
    imgViewToRemove.image = nil;
}
[indexesToRemove removeAllObjects];

UIImageView *imgViewToReplace = [[self.scrollView subviews] objectAtIndex:indexShown];
[imgViewToReplace setImage:[pageUIImagesArr objectAtIndex:indexShown]];
[indexesToRemove addObject:[NSNumber numberWithInt:indexShown]];

if(indexShown != 0 && ![[[self.scrollView subviews] objectAtIndex:indexShown-1] image])
{
    imgViewToReplace = [[self.scrollView subviews] objectAtIndex:indexShown-1];
    [imgViewToReplace setImage:[pageUIImagesArr objectAtIndex:indexShown-1]];
    [indexesToRemove addObject:[NSNumber numberWithInt:indexShown-1]];
}
if(indexShown != kNumImages-1 && ![[[self.scrollView subviews] objectAtIndex:indexShown+1] image])
{
    imgViewToReplace = [[self.scrollView subviews] objectAtIndex:indexShown+1];
    [imgViewToReplace setImage:[pageUIImagesArr objectAtIndex:indexShown+1]];
    [indexesToRemove addObject:[NSNumber numberWithInt:indexShown+1]];
}

currentView = [[self.scrollView subviews] objectAtIndex:indexShown];
//check which view is being shown`

推薦答案

頁面的 UIImage 都保存在一個數組中.

The UIImage's for the pages are all held in an array.

當您將 UIImageView 的屬性設置為 nil 時,UIImage 不會被釋放,因為數組仍然持有一個引用給他們.至于內存增長,可能是正在分配的其他東西.我建議查看 Instrument 的對象分配工具,以追蹤滾動時到底有什么增長.

The UIImage's are not being deallocated when you set the UIImageView's property to nil because the array is still holding a reference to them. As for the memory growth, it may be something else that is being allocated. I'd suggest taking a look with Instrument's object allocation instrument to track down what exactly is growing as you scroll.

這篇關于將 uiimage 設置為 nil 不會使用 ARC 釋放內存的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

how to set scrollview content size in swift 3.0(如何在 swift 3.0 中設置滾動視圖內容大小)
Stop a UITableView from automatically scrolling(阻止 UITableView 自動滾動)
iOS UIScrollView Lazy Loading(iOS UIScrollView 延遲加載)
using iOS 6.0 SDK and building for iOS 5 Target causes UIScrollView setMinimumZoomScale to fail when running on iOS 5 simulator(在 iOS 5 模擬器上運行時,使用 iOS 6.0 SDK 并為 iOS 5 Target 構建會導致 UIScrollView setMinimumZ
Create partial-screen UIPageViewController programmatically(以編程方式創建部分屏幕 UIPageViewController)
how to make an ImageView zoomable with or without ScrollView.?(如何使用或不使用 ScrollView 使 ImageView 可縮放?)
主站蜘蛛池模板: 久久精品中文 | 日韩欧美一区二区三区四区 | 亚洲国产在 | 天天操夜夜操 | 日韩中文字幕 | h视频在线免费 | 婷婷免费在线 | 国产欧美一区二区三区免费 | 亚洲在线一区二区 | 日韩一区二区福利视频 | 久久国产成人午夜av影院武则天 | 在线免费看黄 | 日本91av视频 | 亚洲乱码国产乱码精品精的特点 | 青草福利 | 久久久91精品国产一区二区三区 | 午夜影院视频 | 亚洲欧洲一区二区 | 一级片在线视频 | 欧美日韩精品国产 | 992人人草| 日韩高清成人 | 国产剧情久久 | 99热热99| 91一区二区 | 女人夜夜春 | 亚洲欧洲在线观看视频 | 亚洲高清成人 | 国产伊人精品 | 成人在线观看中文字幕 | 一区二区三区四区五区在线视频 | 亚洲精品福利视频 | 99免费视频 | 久久国产激情视频 | 久久综合久久综合久久综合 | 午夜欧美 | 不卡视频一区二区三区 | 日韩视频a| 欧美性猛交一区二区三区精品 | 精品欧美乱码久久久久久1区2区 | 久久精品欧美一区二区三区不卡 |