if UILabel.text = [different Chinese Strings], memory leak?

喜欢而已 提交于 2019-12-11 17:57:01

问题


I was solving my app's memory leak problem, I narrowed the scope, and found out the "leak" (instruments didn't say leak, but memory went up) came from this method:

- (void)loadDataSource
{
    self.enLabel.text = self.dataSource.en;  // English words
    self.cnLabel.text = self.dataSource.cn;  // Chinese translation
}

The app is a flash cards app. Swipe to switch to next card. Tap to see answer(cnLabel.hidden = NO).

It has only 2 CardView, when prepareing next card, cardView.dataSource will be set, and call this method "loadDataSource".

I did some experiments (50 switch per experiment) on my iphone4:

  1. Baseline: With every switch, the memory went up( ~0.02M per switch );
  2. "return;" at the beginning: memory was OK;
  3. only set enLabel.text: memory was OK;
  4. only set cnLable.text: memory went up;
  5. set cnLabel.text to random NSString made from 8 Chinese characters: memory is OK;

So it seems that the framework reserved something for every different Chinese character.

So my question: Is this normal, or did I just miss something ?

来源:https://stackoverflow.com/questions/16495240/if-uilabel-text-different-chinese-strings-memory-leak

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