更新:2019題目講解方式有所變化,具體請看:Leetcode 題目的正確打開方式 以下是leetcode的題目講解匯總,我會持續(xù)進(jìn)行更新,水平有限,拋磚引玉,歡迎交流: 1...
Student *student = [[Student alloc] init];
[student autorelease];
self.student = student;
[student study];
我覺得,[student autorelease],這里是不對的。
理由:
alloc,new,copy等創(chuàng)建的變量是不加入到自動釋放池當(dāng)中的。
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
[self method1];
[self method2];
}
- (void)method1
{
Student *std = [[Student alloc]init];
self.student = std;
NSLog(@"%@",self.student);
}
- (void)method2
{
[self.student study];
}
我通過,這種作用域的方式去驗(yàn)證過了。
- (void)method2
{
[self.student study];
}
中的self.student,為nil。
說明[student autorelease];這里是應(yīng)該是在處理作用域進(jìn)行了[student release]操作。
[iOS] ARC下系統(tǒng)的內(nèi)存管理策略一.寫在前面的話 今天在寫代碼的過程中意外的見到了奇怪的現(xiàn)象,經(jīng)過深層的剖析發(fā)現(xiàn)這一部分知識還很有用,所以就寫了一篇文章來記錄。 二.代碼演示 1.有如下視圖控制器 2.在V...