NSURLConnection leak?

前端 未结 4 1173
再見小時候
再見小時候 2020-12-13 17:06

i have set up a nsurl which grabs the data from http. when i run instrument, it says i have a leak NSFNetwork object.

and how do i release theConnection

4条回答
  •  既然无缘
    2020-12-13 17:37

    This is a common question and is solved by the magic of [object autorelease]. In your code this would be as follows:

    NSURLConnection *theConnection = [[[NSURLConnection alloc] initWithRequest:theRequest delegate:self] autorelease];
    

    In this way, the object is automatically added to the "autorelease pool" and dealloc'd at the start of the next run loop after it is no longer referenced.

    Hope that helps

    Edit: Also, I don't see why you're needing to call -retain on your receivedData variable.

提交回复
热议问题