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;

     

  • 相关阅读:
    数组返回NULL绕过
    69.x的平方根
    1277.统计全为1的正方形子矩形
    221.最大正方形
    572.另一个树的子树
    983.最低票价
    98.验证二叉排序树
    53.最大子序和
    5386.检查一个字符串是否可以打破另一个字符串
    5385.改变一个整数能得到的最大差值
  • 原文地址:https://www.cnblogs.com/yesihoang/p/4487696.html
Copyright © 2011-2022 走看看