views:

23

answers:

2

According to URL Loading System Programming Guide NSConnection sample code I can release connection in connectionDidFailWithError and connectionDidFinishLoading.

However, releasing connection in connectionDidFinishLoading causing

objc[19685]: FREED(id): message releaseDelegate sent to freed object=0x3b41630
Program received signal:  “EXC_BAD_INSTRUCTION”.

Why?

A: 

This is a double release error. It means either you didn't retain an object enough times, or you sent it too many release messages.

Mike Weller
I understand the nature of error, but all I do is just create `NSConnection` with `connectionWithRequest` and then release in those 2 delegates. The rest of the bodies of delegate methods are empty.
Michael
The general rule is: If you don't create objects using alloc, and don't retain objects, you don't have to release them. They will magically disappear when no-one needs them anymore (with NSAutoReleasePool being the magician and autorelease being the magic spell)
mvds
+1  A: 

If you doesn't retain the object you receive from [NSConnection connectionWithRequest:] then you must not call release on it.

Claus Broch