Simple question - do i need to free or release structs. My reason for asking is that I'm use a NSInvocation and the SEL type is a struct. Just want to know if I need to release it. Thanks.
Objective-C provides two methods of application memory management. In the method described in this guide, referred to as “manual retain-release” or MRR, you explicitly manage memory by keeping track of objects you own.
You can use regular C structs all you want. Your example tries to put references to an Objective-C object, NSString , into a struct , which is incompatible with ARC. Structs are typically used for simple data structures. Examples that you are likely to come across in Objective-C code are CGPoint and CGRect .
The -autorelease message is a deferred -release message. You send it to an object when you no longer need a reference to it but something else might. If you are using NSRunLoop, an autorelease pool will be created at the start of every run loop iteration and destroyed at the end.
In Objective-C and C in general, if something is not a pointer to somewhere else in memory and the whole thing is allocated on stack, you won't need to free it. It'll get freed as soon as the stack pointer is adjusted at the end of function.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With