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

醉酒当歌 提交于 2019-12-13 03:39:46

问题


While an UIView has a memory footprint of at least 4 * width * height pixels, I wonder how that would look when I create a CALayer only.


回答1:


Having done some experimenting around this in the past, I found that the added overhead of the UIView object was very minimal.




回答2:


While an UIView has a memory footprint of at least 4 * width * height pixels

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. The UIView instance variables take up about 24 bytes, and the additional data storage is probably the same, or less.

If UIView adds functionality that's useful for your application, then use it. The memory overhead is really of no concern.



来源:https://stackoverflow.com/questions/1182860/how-much-does-it-matter-regarding-to-memory-if-i-create-an-calayer-rather-than-a

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!