ios - 有点想知道ios上的内存管理

标签 ios memory-management retain

我有很多 View Controller 。

并且它们都有许多保留的属性。

因此,我会将这些代码添加到每个 viewControllers 中:

- (void)viewDidUnload {
    self.every_retained_property = nil;
    [super viewDidUnload];
}
- (void)dealloc {
    [every_retained_property release];
    [super dealloc];
}

到目前为止,我的应用程序一切顺利。

可是我听说了,

a_retained_property = newValue;
// equals to
[a_retained_property release];
a_retained_property = [newValue retain];

所以如果我已经在 viewDidUnload 中将 a_retained_property 设置为 nil,

有必要在dealloc中释放a_retained_property吗,就像我在做的那样?

我只是想知道。

谢谢!

最佳答案

这样说对你没有任何伤害。但是

a_retained_property = newValue;

不等同于:

[a_retained_property release];
a_retained_property = [newValue retain];

你应该使用:

self.a_retained_property = newValue;

关于ios - 有点想知道ios上的内存管理,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9433107/

相关文章:

php - PHP copy()如何处理内存

ios - self.custom View.background 颜色分配导致泄漏?

objective-c - 将 iOS 应用程序移植到 OSX 并维护一组代码?

ios - 我的 iOS 应用程序中的 EXC_BAD_ACCESS KERN_INVALID_ADDRESS

C free() 调用中的无效指针

c# - Hashtable 的内存是如何分配的?

objective-c - Objective C - iOS - UIWebView 保留在 ARC 中,但未调用委托(delegate)方法

php - Codeigniter set_value() 并填充表单值

ios - 从 TableView 执行 segue 时出现延迟或错误

ios - Swift 核心数据删除一对多关系中的条目