When to call release on NSURLConnection delegate?

前端 未结 5 1984
挽巷
挽巷 2021-01-05 22:44

When passing a delegate to the a NSUrlConnection object like so:

[[NSURLConnection alloc] initWithRequest:request delegate:handler];
         


        
5条回答
  •  青春惊慌失措
    2021-01-05 23:21

    It will depend on what object handler is and how you use it. For example, I usually use self as my delegate:

    [[NSURLConnection alloc] initWithRequest:request delegate:self];

    I don't need to call release on self because delegates are not retained and self will be released by another object.

    If handler is a new object, then you will have to release it (and connectionDidFinishLoading: should be ok, unless you need to use the handler object for something else).

    Are you familiar with the rules for memory management in Cocoa?

    Can you give a better picture of what object handler is and how you're using it?

提交回复
热议问题