Objective-c Counter Learning

Source: Internet
Author: User

book.h//Obj-c Learning 1////Created by Itfanr on 14/11/30.//Copyright (c) 2014 ITFANR. All rights reserved.//#import <Foundation/Foundation.h> @interface book:nsobject@property float price;-(ID) Initwithprice: (float) Price; @end
  person.m//  obj-c Learning 1////  created by itfanr on 14/11/ 30.//  copyright  (c)  2014 year  itfanr. all rights reserved.//#import   "Person.h" #import   "Book.h" @implementation  person:nsobject@synthesize book = _book  ;-(void) Setbook: (book *) book{    if (_book != book) {         [_book release] ;        _book  = [book retain] ;    }}    -(Book *) book{ &NBSP;&NBSP;&NBSP;&NBSP;RETURN&NBSP;_BOOK&NBSP;;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP, #pragma   mark  initialization-(ID) initwithage: (int) Age   {    self =  [super  init] ;    _age = age ;         return  self;} #pragma  mark  destroy functions   carbon-  (void) dealloc{   [_book release] ;     nslog (@ "person is dealloced"  );     [super dealloc]  ;} @end
main.m//Obj-c Learning 1////Created by Itfanr on 14/11/29.//Copyright (c) 2014 ITFANR. All rights reserved.//#import <Foundation/Foundation.h> #import "Person.h" #import "Book.h" int main (int argc,    const char * argv[]) {Book *book1 = [[book alloc]initwithprice:4.5];    person * p = [[Person alloc] initwithage:18];    P.book = Book1;    [Book1 release];     [P release]; return 0;}

The output is:

2014-11-30 22:38:11.427 obj-c Learning 1[1228:911238] book is dealloced!2014-11-30 22:38:11.428 obj-c learning 1[1228:911238] person is Deallocedprogram ended with exit code:0

No memory leaks were found.

Objective-c Counter Learning

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.