开发者

memory leak when using NSURLConnection instance

开发者 https://www.devze.com 2023-04-03 08:08 出处:网络
I have an ImageDownloader class with NSURLConnection* connection as an ivar which initializes it setting its delegate as self.

I have an ImageDownloader class with NSURLConnection* connection as an ivar which initializes it setting its delegate as self. Now the doubt is when I init an ImageDownloader instance in my AsyncImageView so that my image downloading is started it has a retain count =2 {1 with image downloader init and 2 with nsurl init setting delegate as self}. So when i release image downloader from my asyncImageView it still has a retain count =1开发者_如何学运维.

How do I release the imageDownloader instance because there is probably a leak? If I release connection ivar in imageDownloader the retain count should be 0 but then the app crashes(for obv. reasons).


Yes, NSURLConnection instance retains its delegate. So you should call [connection cancel] to release it before releasing ImageDownloader instance.

0

精彩评论

暂无评论...
验证码 换一张
取 消