Objective C-内存管理

整理文档很辛苦,赏杯茶钱您下走!

免费阅读已结束,点击下载阅读编辑剩下 ...

阅读已结束,您可以下载文档离线阅读编辑

资源描述

OCiosiosiosmacosiosios(1)OC””1(2)()Cocoaalloc,copyretainCocoa””(retainCount)10Cocoa””(retainCount)10deallocdealloc0dealloc(0)-(void)dealloc{[namerelease];[superdealloc];}dealloc[superdealloc];alloc1alloccopy1retain1release1autorelease111allocPerson*person1=[[Personalloc]initWithName:@””];NSLog(@”nameis%@”,person1.name);//person1[person1release];2Person*person2=[Personalloc]initWithName:@””];NSString*name=person2.name;NSLog(@”%@”,name);//person2[person2release];namenameautorelease1+(id)personWithName:(NSString*)aName{Person*person=[[Personalloc]initWithName:aName];returnperson;}2+(id)personWithName:(NSString*)aName{Person*person=[[Personalloc]initWithName:aName];[personrelease];returnperson;}+(id)personWithName:(NSString*)aName{Person*person=[[Personalloc]initWithName:aName];[personautorelease];returnperson;}-(void)printHello{NSString*str=[NSStringstringWithFormat:@”Hello”];NSLog(@”%@”,str);}@interfacePerson:NSObject{NSString*name;}-(void)setName:(NSString*)aName{if(name!=aName){[namerelease];name=[aNameretain];//orcopy}}retainrelease.-(NSString*)name{returnname;}-(void)printName{NSString*name=person.name;NSLog(@”%@”,name);}1-(void)reset{NSString*newName=[[NSStringalloc]initWithFormat:@”theNew”];name=newName;[newNamerelease];}name2-(void)reset{NSString*newName=[[NSStringalloc]initWithFormat:@”theNew”];[selfsetName:newName];}3-(void)reset{NSString*newName=[NSStringstringWithFormat:@”theNew”];[selfsetName:newName];[newNamerelease];}newNameautoreleasenewNamereleaseretainalloccopyreleaseautoreleasecopyretainallocreleaseautoreleasedeallocautoreleasereleaseSDKInstrument(google)

1 / 24
下载文档,编辑使用

©2015-2020 m.777doc.com 三七文档.

备案号:鲁ICP备2024069028号-1 客服联系 QQ:2149211541

×
保存成功