How to free a block

I save my blocks while my web service is disconnecting and talking to my server. Therefore, I use [myBlock copy] to save a link to my block.

As soon as I receive my data and execute a block, do I call [myBlock release] or use Block_release(myBlock) ? I can find a link to both.

+6
source share
2 answers

Block_release() exists when you use only blocks in C, not Objective-C.

When using Objective-C, you can use the release and copy methods to make your code look and feel more like the rest of ObjC around it.

I assume that they both do the same, and that the objc method is just a wrapper around calling Block_release() anyway.

+9
source

As it is explained in the link, the copy / release amount must be zero. Therefore, if you use Objective-C, you can call [block copy] and therefore [block release] .

If you use C, you should use Block_copy() and Block_release() .

As Jasarien wrote, they probably do the same thing, so you can use them interchangeably. However, it is important that the agreement is consistent, so when you use [block copy] , you would rather use [block release] than Block_release()

+5
source

Source: https://habr.com/ru/post/913904/


All Articles