The purpose of this attribute is intended (but not exclusively) for pointers to dynamically allocated data.
It gives a compile-time guarantee that the calling code will store a pointer in a variable (it can also be a parameter for a function, but I'm not sure), thereby delegating the responsibility of freeing / freeing / deleting the object it points to.
This is to prevent memory leak and / or other aspects of life time management.
for example, if you call malloc (...) without saving the pointer, you cannot release it later. (malloc must have this attribute)
If you use it for a function, return an object, which does not make sense, because the returned object is stored in a temporary state and can be copied to a non-temporary variable (can be optimized) and will always be destroyed (because it will be.
By the way, this is not particularly useful for returned links (if you do not know the code and do not require some kind of release mechanism), since the link object does not collapse when leaving the scope.
source share