首页 > 系统相关 >OC之【内存管理】

OC之【内存管理】

时间:2022-12-09 15:01:42浏览次数:43  
标签:zi 管理 NSLog age OC retainCount stu 内存 Student

Student
@synthesize age = _age; // 在xcode4.5以上环境下可以省略

- (void)dealloc {
@"%@被销毁了", self);

super
// 一定要调用super的dealloc方法,而且最好放在最后面调用,
否则有一些开发者出现闪退现象,就是把[super dealloc]放到了最前面调用了
}
@end



main.m文件:

void
Student *stu = [[Student alloc] init]; // 1

// z代表无符号
NSLog(@"count:%zi", [stu retainCount]);

retain]; // 2

NSLog(@"count:%zi", [stu retainCount]);

release]; // 1

NSLog(@"count:%zi", [stu retainCount]);

release]; // 0

// [stu release]; // 会发生野指针错误,也就是说访问了不属于你的内存
}

void
// Student对象的计数器永远为1,所以不可能被释放
Student alloc] init].age = 10;


Student new].age = 10;

// 上面的代码都有内存泄露
}

标签:zi,管理,NSLog,age,OC,retainCount,stu,内存,Student
From: https://blog.51cto.com/u_15907570/5925322

相关文章

  • OC之【NSObject使用】
    main.m文件#import<Foundation/Foundation.h>#import"Student.h"#import"Person.h"常用方法voidStudent*stu=[[[Studentalloc]init]autorelease];//isKin......
  • OC之【@property的用法】
    1.这里的retain代表:在set方法中,release旧值,retain新值(nonatomic,retain)Book*book;(retain)Card*card;代表只生成get方法的声明默认是readwrite,同时生成get和set......
  • OC之【objective-c中结构体】
    #import<Foundation/Foundation.h>void//定义了Date这种结构体类型structintintint};//定义结构体变量structDated={2013,4,5};day=6;}voi......
  • [附源码]Python计算机毕业设计Django智慧园区运营管理系统
    OverridetheentrypointofanimageIntroducedinGitLabandGitLabRunner9.4.Readmoreaboutthe extendedconfigurationoptions.Beforeexplainingtheav......
  • C# OpenProtocol 开放以太网协议 读写数据 订阅数据
    主要使用的软件是HslCommunication关于这个软件的本身,详细可以参考下面的地址:github地址:https://github.com/dathlin/HslCommunication官网:http://www.hslcommunicatio......
  • Docker-Compose常用命令
    一、Docker-Compose简介  Docker-Compose项目是Docker官方的开源项目,负责实现对Docker容器集群的快速编排。  Docker-Compose将所管理的容器分为三层,分别是工程(projec......
  • node 的管理 nvm
    可以通过以下命令,进行node版本的安装,替换nvmlist//查看已安装的nodejs版本nvmon//启用node.js版本管理nvmoff//禁用node.js版本管理(不卸载任何东......
  • BI智慧仓储,带你体验数字化仓储物流管理
    1、行业背景智能仓储物流是以信息交互为主线,使用条形码、射频识别、传感器、全球定位系统等先进的物联网技术,集成自动化、信息化、人工智能技术,通过信息集成、物流全过程......
  • nginx + graylog 对于日志进行管理的一个实践
    以下整理一个自己结合ngin+graylog进行日志处理的实践,可以参考日志参考玩法   参考配置logformat参考如下,可以配置一些符合自己业务的logformat不同业务......
  • [附源码]Python计算机毕业设计Django疫情物资管理系统
    OverridetheentrypointofanimageIntroducedinGitLabandGitLabRunner9.4.Readmoreaboutthe extendedconfigurationoptions.Beforeexplainingtheav......