我已经阅读了很多关于保留周期的内容。必要时,父级UIViewController
应始终对其子级strong
具有UIViewController
引用,而子级则应对其父级weak
提及UIViewController
。
仅当他们互相引用时才这样吗?例如,如果父级strong
没有任何对其子级的引用,那么该子级是否可以对其父级UIViewController
进行Task.cs
引用?我能否解决这个问题,或者从长远的内存问题来看这是不好的做法?
答案 0 :(得分:3)
来自function getCookie(cname) {
var name = cname + "=";
var ca = document.cookie.split(';');
for(var i = 0; i <ca.length; i++) {
var c = ca[i];
while (c.charAt(0)==' ') {
c = c.substring(1);
}
if (c.indexOf(name) == 0) {
return c.substring(name.length,c.length);
}
}
return "";
}
。
UIViewController.h
和
/*
If this view controller is a child of a containing view controller (e.g. a navigation controller or tab bar
controller,) this is the containing view controller. Note that as of 5.0 this no longer will return the
presenting view controller.
*/
weak public var parentViewController: UIViewController? { get }
您可以在此处看到,父母与子// An array of children view controllers. This array does not include any presented view controllers.
@available(iOS 5.0, *)
public var childViewControllers: [UIViewController] { get }
之间已经已经 strong
和weak
引用。您不应在从子级到父级的方向上添加任何新的ViewControllers
引用,因为它可能导致内存泄漏。