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;

     

  • 相关阅读:
    OpenGL完整实例
    OpenGL
    Socket(2)
    Socket(1)
    Stream,Reader/Writer,Buffered的区别(2)
    Stream,Reader/Writer,Buffered的区别(1)
    SQLite数据库与Contentprovider(2)
    SQLite数据库与Contentprovider(1)
    数据存储和访问
    AIDL与service
  • 原文地址:https://www.cnblogs.com/yesihoang/p/4487696.html
Copyright © 2011-2022 走看看