Need to free an IBOutlet object?

I have a dilemma about freeing an IBOutlet object for memory. Someone please suggest what to do when we create an IBOutlet object without a property, do I need to release it? if you need to free ... why do we release it

+4
source share
8 answers

Answer: YES.

Runtime associates objects with IBOutlet using [setValue:ForKey:] . This function will find the private instance variables, save the target and set it to the instance variable. Please visit the iOS Developer Library to find out more.

I highly recommend that you read the article because many iOS structures access properties using key matching ( [setValue:ForKey:] or [valueForKey:] ) instead of directly calling getters / setters / instance variables.

+4
source

IBOutlet does not change the semantics of property properties. If you are not using ARC, you need to free the stored objects, as with any other property.

+1
source

Just set it as default, which is weak. Then everything is fine with ARC.

+1
source

Why not just have your own IBOutlet property to make things more clear and more explicit. I always do it personally:

 MyClassName.m @interface MyClassName () @property (nonatomic, weak) IBOutlet NSObject *myPropertyNameForAnOutlet; @end @implementation MyClassName ... @end 
+1
source

The answer is YES ...

I was confused too, but try the following:

open xib file

assistant editor window window and get the .h file code next to your XIB IB file

selected an object in the IB file (an object without a link to any var)

ctrl click on it and select: "new link" button

drag the line to the .h code file in the @interface {} section

enter a name for your new var ("aaa")

(note that no property "aaa" was created)

now Xcode has done all the magic for you and ...

in the .m file, you can find in the dealloc method:

 - (void) dealloc { [aaa release]; [super dealloc]; } 

So ... if Apple releases it, it seems that by default IBOutlet files downloaded through the XIB file are saved ...

EDIT:

here is the dot in the apple document :

+1
source

You are not the owner of this property. therefore there is no need to issue an IBOutlet object. If you use @property (non-atomic, save) in an IBoutlet object, you must release this object in dealloc.

See Advanced Memory Management Programming Guide
You must not waive ownership of an object you do not own

+1
source

You do not own the property, so do not release it.

You become the owner by saving, copying or creating (init / alloc) an object. Only then you are (one of) the owner (s) of the object and must release it when you are done with the object. More information Cocoa core competencies - memory management

Hope this explains why you don't need to let go of the object.

0
source

Even if you did not set it as a property, the property refers to the setter and getter methods. When you use an object, you should always keep in mind its release. The property is not related to a memory problem.

-1
source

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


All Articles