iOS Memory issue (ARC) when downloading and saving large ammount of images from server

后端 未结 2 644
猫巷女王i
猫巷女王i 2021-02-04 21:04

The following code downloads 700+ images from a server with varying sizes, the issue here is that memory (even with ARC) is never released and eventually a memory warning appear

2条回答
  •  孤独总比滥情好
    2021-02-04 21:35

    "dataWithContentsOfURL" returns an autoreleased NSData object and that doesn't normally get released until the end of the run loop or the end of the method, so it's no wonder you're filling up memory pretty quickly.

    Change it to an explicit "initWithContentsOfURL" method and then force a release by doing "data = nil;" when you are absolutely done with the image data.

提交回复
热议问题