一道经典的 NSString 内存面试题

1/3,

objectivec 复制代码
@property (nonatomic, strong) NSString* strA; 
@property (nonatomic, strong) NSString* strB;

self.strA = @"strA"; 
self.strB = self.strA; 
self.strA = nil;
NSLog(@"self.strB 的值是%@", self.strB);

// self.strB 的值是strA

2/3,

objectivec 复制代码
@property (nonatomic, strong) NSString* strA; 
@property (nonatomic, weak) NSString* strB;

self.strA = @"strA"; 
self.strB = self.strA; 
self.strA = nil;
NSLog(@"self.strB 的值是%@", self.strB);

// self.strB 的值是strA

3/3

objectivec 复制代码
@property (nonatomic, strong) NSString* strA; 
@property (nonatomic, weak) NSString* strB;

self.strA = [NSMutableString stringWithString: @"strA"];
self.strB = self.strA; 
self.strA = nil;
NSLog(@"self.strB 的值是%@", self.strB);

// self.strB 的值是(null)
相关推荐
宋艳_AI应用开发2 小时前
Agent 工程:慢的不一定是模型,答案对了也可能算失败
面试
斯维赤5 小时前
三级缓存为什么是三级?二级缓存不够吗
前端·后端·面试
前端小万9 小时前
思考,行动,复盘|2026
前端·后端·面试
Sailing9 小时前
🚀客户端都超时了,你的 Go 服务还在查库?Context 取消链路不打通,连接池迟早被打爆
后端·面试·go
Baihai_IDP10 小时前
使用场景不同,模型“推理速度慢”的原因也不同
人工智能·面试·llm
Rain的Java大神之路10 小时前
别被 ChatGPT 的打字机效果骗了:一字一字蹦,才是 LLM 自回归的命门(附大厂 Java 流式落地)
java·后端·面试
nice_lcj52020 小时前
MySQL 的锁:行锁、表锁、间隙锁与死锁
mysql·面试·锁·行锁·死锁·间隙锁
ShineWinsu1 天前
对于Qt:QSpacerItem常见属性以及方法的解析
开发语言·c++·qt·面试·系统架构·客户端·qspaceritem
某哈压力大1 天前
移动端 rem 适配
前端·vue.js·面试
nice_lcj5201 天前
【从零理解计算机网络 · 02】分层模型:别背 OSI 七层,看数据怎么被“打包“和“拆包“
java·后端·tcp/ip·计算机网络·面试·osi·分层模型