久久久久久久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 可縮放?)
主站蜘蛛池模板: 国产成人在线一区二区 | 国产亚洲精品成人av久久ww | 人妖一区 | 另类亚洲视频 | 欧美日本韩国一区二区 | 一级片aaa | 久久久爽爽爽美女图片 | 中文字幕国产第一页 | 亚洲一区二区三区在线播放 | 色偷偷888欧美精品久久久 | 在线黄色影院 | 日韩亚洲一区二区 | 成年男女免费视频网站 | 国产精品毛片无码 | 亚洲精品一 | 国产午夜三级一区二区三 | 97视频精品 | 欧美一区二区大片 | 日韩精品无码一区二区三区 | 狠狠的日 | 国产伦精品一区二区三区高清 | 亚洲成人一级 | 午夜丰满寂寞少妇精品 | 欧美一区二区三区 | a级免费视频 | 一区二区在线看 | 欧美a区| 夜夜摸夜夜操 | 亚洲网址在线观看 | 久热精品免费 | 成人久久久 | a在线观看 | 欧美激情一区二区 | 中文字幕一区二区三区精彩视频 | av天天干 | 欧美精品欧美精品系列 | 日本精品一区二区 | 毛片网在线观看 | 岛国av免费在线观看 | 精品久久久久久久久久久久 | av片免费观看 |