代码ARC+1:—1:0

/***********************************************************************************************************************************

**********************************************************************************************************************************/

copy  +1

new   +1

alloc   +1

retain   +1

release  -1

autorelease  -1

/***********************************************************************************************************************************

**********************************************************************************************************************************/

@(property) NSString* myStr;

@(property) NSString* myStr2;

+(NSArray*)   array {

NSArray *array = [[NSArray alloc] init ]; +1

return [array autorelease];  -1

}

int main() {

self.myStr = [NSString stringWith:@abc];  //1

self.myStr = [NSString stringWith:@deffffff];

//[self setMyStr:[NSString stringWith:@abc]];

//void setMyStr ( NSString *str ) {

// [_myStr release];

// _myStr = str;

// [_myStr retain]

//}

self.myStr2 = self.myStr;

//void setMyStr2 ( NSString *str ) {

// [_myStr2  release];

// _myStr2  = self.myStr;

// [_myStr2 retain]

//}

[self.myStr release];

[self.myStr2 release];

}

void show () {

UIButton *button = [UIButton button]; //0

[array addObject : button];  //button + 1

//[button retain];

//数组中放的对象  必须是继承了 NSObject

[array1 addObject : button];  //button + 1

}

void show1() {

button.tag = 100;

[array removeObject:button];  //button - 1

}

/***********************************************************************************************************************************

**********************************************************************************************************************************/

Retain

Release

AutoRelease

autoreleasePool

/***********************************************************************************************************************************

**********************************************************************************************************************************/

UIButton *button = [[UIButton alloc] init]; +1

UIButton *button = [[UIButton button] init]; 

+UIButton* buttonWithImageName:(NSString*)imageName {

UIButton *button = [[UIButton alloc]init]; +1

[button autorelease]; -1

return button;

}

_button =  [[UIButton button] init];  //0

self.button  =  [[UIButton button] init];  //1

[self setButton:[[UIButton button] init]]; //1


UIButton button2 = [[UIButton alloc] init]; //1

self.button = button2;

void setButton: button2  {

[_button release];

_button = button2;

[button2 retain];

}

[button2 release];


UIView *view = [UIView view]; //0

UIButton *button3 = [[UIButton alloc] init]; //1

UIButton *button4 = [[UIButton alloc] init]; //1

//[view addSubView:button3];


NSArray *array = [NSArray array];

[array retain];

[array addObject:button3]; //2

[array replaceAtIndex:0 Object:button4]; //3(1) 4(2)

[array removeObject:button4]; //1


NSArray *arr2 = array;

[arr2 retain];

[arr2 addObject:button3];

/***********************************************************************************************************************************

**********************************************************************************************************************************/

retain

release

autorelease

/***********************************************************************************************************************************

**********************************************************************************************************************************/

alloc  new  copy

字典  数组  

[View addsubViewview];

set方法

-(void) setUIImageView:imageView;


class Test{

@(property) UIImageView* myImage;

}

UIImageView* _myImage;

-(UIImageView*) myImage {//get方法

return _myImage;

-(void) setMyImage:(UIImageView*)imageVIew {

//判断是否自负值

if(_myImage = imagerView )  return; //释放原有内存空间, 指针指向的原来的对象的 引用计数器-1


[_myImage release];

//拷贝地址

_myImage = imageView;

//给指针指向的新的对象的 引用计数器+1

[_myImage reatin]; 

}


void init{

_myImage = [UIImageView imageView]; 

self.myImage  = [UIImageView imageView]; 

self.myImage =  [[[UIImageView alloc]init ] autorelease]; 

_myImage = [[UIImageView alloc]init ] ;//1

}


void test{

_myImage

}

/***********************************************************************************************************************************

**********************************************************************************************************************************/

Retain

Release

AutoRelease

autoreleasePool

/***********************************************************************************************************************************

**********************************************************************************************************************************/

UIButton *button = [[UIButton alloc] init];  +1

UIButton *button = [UIButton button]; 0


_button = [UIButton button];   0

_button = [[UIButton alloc] init];  1

self.button = [UIButton button];   1

self.button = [[[UIButton alloc] init] autorelease];  1


+UIButton* button {

UIButton *_button = [[UIButton alloc]init]; 1

[_button autorelease];

return _button;

}

事件?

开始触摸 事件开始 创建自动释放池

autoreleasePool *pool = [[autoreleasePool alloc] init];

创建button 调用了 button 类方法

[pool addReleaseOjbect: button]

抬起触摸 事件结束 释放自动释放池

NSArray *array = [pool releaseOjbects];

for(int i = 0; i < array.count; i++) {

NSObject *object = [array objectAtIndex:i];

[object release];

}

[pool release] 


UIButton *button1 = [[UIButton alloc] init];  1

UIButton *button3 = [[UIButton alloc] init];  0

self.button3 = button1;

[self setButton3:button1];

void setButton3{

  [button3 release];

button3 = button1;

[button1 retain];

}


{ // 1 执行

self.view = [UIView view];   1

_button = [UIButton button];  0

[view addSubView:button];   // [button retain]

}

{ // 2 执行

[view removeSubView:button];  // [button release]

}

{ // 3 执行

_button; 该对象能不能访问到  

}

{ // 1 执行

self.array = [NSArray *array];   1

_button = [UIButton button];  0

[array addObjcet:button];   // [button retain]

}

{ // 2 执行

[array removeObject:button];  // [button release]

}

{ // 3 执行

_button; 该对象能不能访问到  

}

/***********************************************************************************************************************************

**********************************************************************************************************************************/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值