Memory leak NSAutoreleasePool

前端 未结 2 442
臣服心动
臣服心动 2021-01-28 20:19

With instruments i got a memory leak on this piece of code and i don\'t understand why!

-(void)goToThisUrl:(id) targetUrl
{
    NSAutoreleasePool *pool = [[NSAut         


        
2条回答
  •  野趣味
    野趣味 (楼主)
    2021-01-28 20:44

    First off, you can't allocate a UIImage in a second thread. Uses of UIKit need to be on the main thread. I assume what you wanted to do by creating another thread was to invoke dataWithContentsOfURL without blocking the main thread. But, this is not the right approach. Instead, use a NSURLConnection with an async callback that gets invoked when the download is done. Apple already provides a built-in "download" thread that NSURLConnection uses behind the scenes. So, your approach of creating another thread to download is pointless.

自定义标题
段落格式
字体
字号
代码语言
提交回复
热议问题