zoukankan      html  css  js  c++  java
  • 内存管理2-@class关键字

    Review:

    给对象发送消息,进行相应的计数器操作。

    Retain消息:使计数器+1,改方法返回对象本身

    Release消息:使计数器-1(并不代表释放对象)

    retainCount消息:获得对象当前的引用计数器值

    Management principles:

    1 alloc new copy

    who create ,who release

    2 except (alloc new copy)

    Please state autorelease

    3 Who retain,who release (anyway)

    ------------------------------------------------------

     @class  ---->Key word

    // Add content

    //When use dealloc

    -(void)dealloc{

    //self.book=nil;->OK

    //[self setBook:nil];->OK

    [_book release];

    [super dealloc];

    }

    //Because self.book =setBook . It's a method inside can release book,not visiting //mumber variable.

    -(void) setBook:(Book *)book{

    if(_book!=book){

    [_book realease];

    _book=[book retain];

    }

    }

     ------------------------------------------------------

    @class

    In Student.h file

    General in development #import "Book.h" will cause some problem in property.

    #import "Book.h"

    will copy all the things and most of them is useless.

    And we want only know Book is a class,I don't want know other things(inheritation&getter&setter)

    So in Student.h

    Replace  #import "Book.h"; as @class Book;

     

  • 相关阅读:
    JavaScript中的this相关
    Git进阶操作_1
    Git基本操作_5
    Git基本操作_4
    Git基本操作_3
    Git基本操作_2
    利用Python发送SMTP邮件
    Python JWT使用
    Python中的Asyncio 异步编程
    Python中的抽象类和接口类
  • 原文地址:https://www.cnblogs.com/yesihoang/p/4487696.html
Copyright © 2011-2022 走看看