简体   繁体   English

如果创建CALayer而不是UIView,那么对内存有多大影响?

[英]How much does it matter regarding to memory if I create an CALayer rather than an UIView?

虽然UIView的内存占用量至少为4 *宽*高像素,但我不知道仅创建CALayer时的外观。

过去对此进行了一些实验,我发现UIView对象的额外开销非常小。

While an UIView has a memory footprint of at least 4 * width * height pixels 虽然UIView的内存占用量至少为4 *宽*高像素

This statement is absolutely not true. 这个说法绝对是不正确的。 The memory overhead of a UIView (compared to a CALayer) is just the size of the instance variables of the UIView class, plus a few instances of additional classes that will get allocated. UIView(与CALayer相比)的内存开销只是UIView类的实例变量的大小,加上一些将要分配的其他类的实例。 The UIView instance variables take up about 24 bytes, and the additional data storage is probably the same, or less. UIView实例变量占用大约24个字节,并且其他数据存储可能相同或更少。

If UIView adds functionality that's useful for your application, then use it. 如果UIView添加了对您的应用程序有用的功能,请使用它。 The memory overhead is really of no concern. 内存开销确实无关紧要。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM