更改 UITextView 的字体大小会泄漏内存
我有一个滑块用于更改 UITextView 中文本的字体大小。分析器和泄漏报告没有内存泄漏。但是,每次我通过移动滑块更改字体大小时,内存都会增加。最终该应用程序收到内存不足警告。代码是:
mainText.font = [UIFont systemFontOfSize:mainSlider.value];
如果我用 mainText.font = [UIFont systemFontOfSize:40.0];
替换该代码,则无论我移动滑块多少次,内存都保持不变。我搜索了这个网站和许多其他网站,寻找有关可能的 UIFont 错误的信息。没有成功。我看到人们使用与我相同的代码,但没有提到增加内存。请帮忙。
I have a slider used to change the font size of the text in a UITextView. Analyzer and Leaks report no memory leak. However, the memory grows each time I change the font size by moving the slider. Eventually the app gets an out of memory warning. The code is:
mainText.font = [UIFont systemFontOfSize:mainSlider.value];
If I replace that code with mainText.font = [UIFont systemFontOfSize:40.0];
, memory stays the same no matter how many times I move the slider. I searched this and many other sites looking for info on a possible UIFont bug. No success. I see people using the same code I am using and not mentioning increasing memory. Please help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
可能有一个字体缓存,以避免一遍又一遍地重新生成相同的字体(有点像 [UIImage imageNamed:@""]),
文档中没有明确说明,但阅读
可以让人相信有一个缓存
http: //developer.apple.com/library/ios/#documentation/UIKit/Reference/UIFont_Class/Reference/Reference.html
另外,你所说的“out”是什么?内存警告”?我认为这只是一个“内存警告级别=1”,而不是由于内存不足而导致应用程序崩溃?
There is probably a font cache in place to avoid regenerating the same fonts over and over again (a bit like [UIImage imageNamed:@""])
It is not explicitly stated in the docs but reading
could make one believe there is a cache
http://developer.apple.com/library/ios/#documentation/UIKit/Reference/UIFont_Class/Reference/Reference.html
Also, what are you calling an "out of memory warning"? I presume it's just a "memory warning level=1", and not an application crash because of out-of-memory?