简体   繁体   中英

deallocation function in xcode 4.1

I have recently been trying to learn objective C for iphone development, however I have bought a book on iPhone 3 development so it is outdated. I have noticed differences in code layout from the book examples and the xCode default code. My question is to do with the -void (dealloc) function.

I have created a basic "view based" project and in my book it states that in my viewController.m file there is a "dealloc" function however in xcode 4.1 there is no dealloc function in viewController.m the only dealloc function to be found id in the AppDelegate.m file.

So my question is, finally:

If i synthesize an instance variable in view controller.m

    @synthesize nameField;

do I then create a dealloc function in viewController.m to release that variable like so?

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

It depends if the property you declared for nameField was assign, retain or copy (you should look into the memory management guide to gain an understanding of this). Basically, if the property is retain or copy then you should release it in the dealloc method. Otherwise you shouldn't.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM