- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我的 iPad 应用程序中有一些全屏 UIColor PatternImages
(在 scrollViews
中),并且遇到了一些内存问题(惊讶吗?)
当我开始出现内存问题时,我在 ScrollView 中实现了延迟加载。
当问题继续存在时,我放弃了工厂方法(如[UIColor colorWithPatternImage:...]
)“分配”方法(如[[UIColor alloc]initWithPatternImage:...]
),这样我就可以通过释放页面来响应内存警告。
但是,每当我释放 UIColor PatternImages 时,我都会收到 “EXC_BAD_ACCESS”
错误。
起初我认为这可能是由我的 [UIImage imageNamed:...]
图案图像引起的,所以我切换到 [[UIImage alloc]initWithContentsOfFile:...]
图像,但这没有帮助。刚才我设置了 NSZombiesEnabled
它告诉我问题是:
-[UICGColor release]: message sent to deallocated instance 0x187b50
使用回溯:
#0 0x35823910 in ___forwarding___ ()
#1 0x35823860 in __forwarding_prep_0___ ()
#2 0x357e53c8 in CFRelease ()
#3 0x357e48de in _CFAutoreleasePoolPop ()
#4 0x3116532c in NSPopAutoreleasePool ()
#5 0x341a7508 in _wrapRunLoopWithAutoreleasePoolHandler ()
#6 0x3580ac58 in __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ ()
#7 0x3580aacc in __CFRunLoopDoObservers ()
#8 0x358020ca in __CFRunLoopRun ()
#9 0x35801c86 in CFRunLoopRunSpecific ()
#10 0x35801b8e in CFRunLoopRunInMode ()
#11 0x320c84aa in GSEventRunModal ()
#12 0x320c8556 in GSEventRun ()
#13 0x341dc328 in -[UIApplication _run] ()
#14 0x341d9e92 in UIApplicationMain ()
#15 0x00002e5e in main (argc=1, argv=0x2fdff610) at...
我也没有任何 UICGColor
对象,所以我认为我的“分配”的 UIColors
具有底层 UICGColor
自动释放对象...?有什么想法/见解吗?
最佳答案
我也遇到了同样的问题,这就是我优化代码的方法。
在 Instruments 中进行一些分析和调试后,我发现 colorwith 模式将占用 1.12 mb,并且有一个名为 ripl_create 的负责库。对于带有 colorWithPattern 的每个屏幕,将占用相同的 1.12,因此您将分配多个 oj 1.12 mb。这糟透了我的应用程序。所以我决定不使用 colorWithPattern。
我猜你想将图像设置为 View 的背景。我建议保留一个 ImageView 并将图像放置到其中...
现在进行 imageView 优化
如果您希望该图像在应用程序的许多部分中使用,或者包含该图像的 View 将被频繁访问,那么请使用 imagenamed。
imageNamed 会缓存图像,即使你将其置空或释放也不会释放它。
在另一种情况下,您希望发布图像
在viewWillAppear或viewDidLoad中将图像分配给imageview
NSString *fileLocation = [[NSBundle mainBundle] pathForResource:@"yourImage" ofType:@"png"];
imageView.image = [UIImage imageWithData:[NSData dataWithContentsOfFile:fileLocation]];
在你的viewDidDisappear中设置nil来释放图像
imageView.image=nil;
关于iphone - 释放 UIColor PatternImage 的正确方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4795470/
我正在为 UIColor 编写一个简单的扩展,以获取基于 this answer 的十六进制字符串: import UIKit extension UIColor { public stati
例如,下面的代码与 UIColor.Purple 或 UIColor.Yellow 一起工作正常,但当我使用 UIColor.black 时应用程序崩溃。 fatal error :索引超出范围使用
这个颜色 [UIColor colorWithRed:75.0/255.0 green:215.0/255.0 blue:100.0/
使用 self.backgroundColor = .init(named: "my-color") 其中 self 是一个 UIView,触发此错误: Value of optional type
我正在尝试使用以下代码创建一个 UIColor 实例: var someColor:UIColor = UIColor.colorWithAlphaComponent(0.3) 预编译器告诉我有错误。
我有一个带有 UIColor 属性的对象: class Beer: NSObject { var color: UIColor? ... } 我正在将其保存到数据库中,因此我需要将此属性转换为
这个问题已经有答案了: Swift UIColor initializer - compiler error only when targeting iPhone5s (2 个回答) 已关闭 8 年前
我在 View Controller 类中设置标签颜色。当我使用以下代码时,它起作用了。 self.labelTest.textColor = UIColor.red 但是,如果我使用 UIColor
我想在饼图中提供自定义颜色(使用图表 Pane )。但是为此,setColors([NSUIColor]) 中的数组需要 NSUIColor 格式的颜色数组,我有颜色的十六进制代码。如何使用十六进制代
我正在尝试从 rgb-hex 色彩空间实现 CIColor,如下所示: let bottomColor = UIColor.init(red: 235/255, green: 250/255,
在我的应用程序中,我尝试使用不同的颜色进行绘制。我有自己的颜色选择器,但我想将颜色亮度添加到此选择器 slider 。对于 understudying :我选择一种颜色显示在 View 中的某个地方作
UILabel label = new UILabel(); label.TextColor = UIColor.Black; 如何以字符串格式存储 UILabel 颜色?我想从数据库中获取该颜色并
我无法从使用工厂方法创建的 UIColor(带有模式)创建 NSData 对象 [UIColor colorWithPatternImage:image] 适用于标准 UIColor 对象。想知道是否
我在将 uicolor 转换为十六进制颜色时遇到问题,这是我发现的 CGColorRef colorref = [[Colorview_ backgroundColor] CGColor]; int
我正在绘制一个饼图,每个切片都有不同的颜色。我需要给切片带来纹理外观,而不仅仅是纯色。有什么想法如何做到这一点?我不想使用图像作为所有可能颜色的纹理。所以我需要生成纹理或类似的东西。有任何想法吗。谢谢
我有一个十六进制颜色值,我想将其转换为 UIColor。 UIColor 可以接受色相/饱和度/亮度 (HSB) 值或红/蓝/绿 (RGB) 值。如何使用十六进制值创建 UIColor? 最佳答案 有
我正在涉足 Android 的 MonoTouch/Mono,目前正在创建我自己的 UIColor 子类。不知何故,我无法让我的工厂方法以我想要的方式工作(但我确实有一个解决方法)。 以下代码导致我崩
我已经构建了一组自定义颜色以在我的应用程序中使用,例如石灰 mylimeColor = [UIColor colorWithRed:0.502 green:1.000 blue:0.000 alpha
我正在制作一个交互式应用程序,它应该显示一个蓝色的 UILabel,当按下某个按钮时它必须消失。当我们继续按下按钮时,标签的颜色应该会褪色。我尝试创建自定义 UIColor 并更改其亮度,但效果并不理
尝试简化每个单元格行对象着色的实现。这就是我当前向每行中的对象添加颜色的方式: progressViewLeft.primaryColor = Colors.Stage1 “Colors”是一个像这样
我是一名优秀的程序员,十分优秀!