Is there any performance or memory overhead using UIImage or UILabel or NSString in Quartz2D

纵然是瞬间 提交于 2019-12-24 10:23:08

问题


Is there any performance or memory overhead using UIImage or UILabel or NSString in Quartz2D.

If there is no difference then why not use UIImage, UILabel etc.

Can any one send me the snippet how to draw image without using UIImage.

Thanks in advance, Regards.

please correct me if you see any stupid mistake I am new to this, trying to learn it.


回答1:


A label draws a string. You can't have a label without a string; if you did, what would it draw?

Last I checked, UILabel uses UIWebView internally, so you could indeed make a more efficient version. One way would be to use Core Text; the other would be to use a CATextLayer.

As for UIImage, technically yes; a UIImage wraps a CGImage, so cutting out the UIImage would save some memory. However, 99% of the memory used by an image is for the image itself, its pixels; those are contained within the CGImage, and the UIImage is tiny compared to it. You have better things to spend your time cutting.

Rather than guessing and/or relying on generalities for your optimizations, use Instruments to find out exactly what your application is spending its memory on. Once you know with hard evidence where all your memory is going, you'll know where you can look for savings.

Wrappers generally won't increase memory usage much; objects are small, so you'll only pay a lot for them if you create a lot of them. Look instead to shortening their lifetimes; don't hold onto objects (in caches, collection objects, or directly in instance variables/properties) any longer than you need to.



来源:https://stackoverflow.com/questions/9477734/is-there-any-performance-or-memory-overhead-using-uiimage-or-uilabel-or-nsstring

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