• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
Yesi-悦思
"(program(computers) == *art) ? so : what" 修身岂为名传世,作事惟思利及人
博客园    首页    新随笔    联系   管理    订阅  订阅

内存管理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;

 

posted @ 2015-05-08 14:48  悦思  阅读(133)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3