Memory continuously increase then app crash when i display image from document directory during scrolling UITableview

后端 未结 3 1533
臣服心动
臣服心动 2021-01-19 15:18

My Requirement is download all images in application memory and display it from local if its available.

Below is my code to access image from local and if its not av

3条回答
  •  醉梦人生
    2021-01-19 16:04

    It's possible that UIImagePNGRepresentation returns non-autoreleased object - you can try to release it and see if that results in a crash. Obviously you are not releasing something, but nothing other than the image representation appears obvious.

    A few other comments:

    • run your app in Instruments, using the ObjectAlloc tool, and it should be immediately obvious what objects are not dealloced. If you don't know Instruments, well, its time now to learn it.

    • you can 'track' objects and get a message when they are dealloced using ObjectTracker - however it was designed for ARC so you may need to tweak it. If you use it you would see a message when each of your objects are dealloced

    • when the table view is done with a cell, there is a delegate method that you can receive that tells you so, and you can then nil (release) and objects the cell retains

    • your use of downloadQueue is bizarre - create it once in your instance as an ivar, use it as you need, and in dealloc release it

    • you hide the activity spinner on the main queue, but don't start it on the main queue

    • you command the activity view to remove itself from its superview, but then look for in in the subviews and try to remove it there:

    [self.activityView removeFromSuperview];

    for (UIView * view in self.subviews)
    {
        if([view isKindOfClass:[UIActivityIndicatorView class]])
            [view removeFromSuperview];
    }
    

    In the end, Instruments is what you want. You can read up more about it here, or just google and you will surely find a slew of blogs to read.

提交回复
热议问题