After ARC, how can you still reference the freed object by mistake?

Is it possible? I mean, weak pointers are automatically nullified. Strong pointers are only freed when indicated elsewhere.

Can we still have an error when pointing to freed objects?

__ unsafe_unretained are performed by those who know what they are doing. So this is not a mistake.

+4
source share
2 answers

__ unsafe_unretained, CFTypeRefs, malloc () ed memory

+4
source

Beware of __autoreleasing vs @autoreleasepool. The compiler is not smart enough to save the value of the __autoreleasing variable when the autostart pool is drained. This includes @autoreleasepool inside the method with the NSError ** parameter.

Beware of the __ block __ of implementing variables. This includes a block object that sets the variable NSError **. Some blocked APIs wrap a block call in an autodetection pool, so you get the same drawback as above.

Beware of an API that is virtually unsafe - not available. For example, many delegate pointers in AppKit and UIKit are unsafe and not nullified. If you arrange the object diagram incorrectly, it will work when the delegate object is released and the collection attempts to use it.

Beware of arrayed C pointers of object pointers. This can be done correctly, but if you are not careful, you will get leaks or crashes.

Beware of the noble races. If you have a multi-threaded error, all bets are disabled.

+13
source

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


All Articles