一道经典的 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)
相关推荐
Cosolar15 小时前
不收费、不加水印、数据归你:我做了个开源的在线简历工具
后端·面试·前端框架
行走的陀螺仪16 小时前
【转型攻略】2026 年,后端 / 全栈工程师转 AI Agent 方向:能力地图、按周学习路线与面试要点
人工智能·面试·职场和发展
考研保研资料分享17 小时前
法学保研中国人民大学诉讼法:英语讨论、辩论与两校笔试
面试
kyriewen19 小时前
我把 10 道面试题答案真跑了一遍:6 道是错的
前端·javascript·面试
zhippt_101420 小时前
图转PPT怎么把截图变成可编辑幻灯片?技术路线与实测拆解
面试
考研保研资料分享1 天前
2025数学保研北交大:三校预推免、英文自介与方向选择
面试
秋饼1 天前
MySQL 分库分表完全指南:ShardingSphere-JDBC 实战、分片键选型、场景边界、20 个生产坑与 30 道面试点
java·mysql·面试·shardingsphere·分库分表·后端架构
ShineWinsu1 天前
对于Qt:QWidget通用属性的解析—上
数据库·qt·microsoft·面试·gui·属性·qwidget
IT规划师1 天前
MQTT实战 - MQTT高频面试题 + 我的8年实战答案(十一)
物联网·mqtt·面试·.net core·iot·mqttnet