Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Objective C Structs and Memory Management

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.

like image 775
Brian Avatar asked Aug 19 '09 19:08

Brian


People also ask

Does Objective-C have memory management?

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.

Can you use structs in Objective-C?

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 .

What is Autorelease Objective-C?

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.


1 Answers

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.

like image 152
mmx Avatar answered Sep 20 '22 14:09

mmx