0

I want to show some images that user saved in his Document directory in a uitableview. I use below simple code:

    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
    {
        static NSString *cellIdentifier = @"uploadHistoryCellfa";

        BRUploadHistoryCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
        if (!cell) {
            cell = [[BRUploadHistoryCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
        }

       //Some Other assignemt to UILables Here...

        [cell.imagePreview setImage:[UIImage imageWithContentsOfFile:myImagePathInDocument]];

       //Some other configurations here ....

        return cell;
    }

my question is that:

The images size is about 11-25 MB. and I will load one image at each cell. Does this code that I use potentially can cause memory leak or some thing like this?

Husein Behboudi Rad
  • 5,434
  • 11
  • 57
  • 115

2 Answers2

0

If only 1-2 cells are shown in screen at a time then it won't cause you much trouble. As TableView will update the contents of already created cells with new Images. (Deque Reusable Concept)

But the better Approach will be to resize the Images first and then use.

Piyush Sharma
  • 1,891
  • 16
  • 23
0

11-25 MB is large file actually if you have UITableView you will have more then 5 images so it will become 11-25 (*5) so you should resize images while adding them on tableView, but if you will resize it in proccess of showing it will slow up your app. So you first step is to save resized image which will size of max 1 mb. Second Step is to generate thumbnail and after that add thumbnail image on cell.

First Link: Resize Image

Second Link: Image Resizing Techniques

imageIO for my practice is fastest way to resize image because it uses CPU and user will not see slow scrolling problem.

After all steps done do not forget to use foreground thread and main thread for representing images on cell.

Community
  • 1
  • 1
C0mrade
  • 1,215
  • 1
  • 10
  • 23