2
  • I have a CATextLayer from the size of 3000 * 3000 with a Big Text in it.
  • Text is say "Hello"
  • I add this CATextlayer to my Superlayer.
  • I have set shouldrasterize to false.

When moving the superlayer with translation, then I observe a huge Memory Usage till the app crashes.

Why does this take that much memory ? How can I avoid that ?

I assume, there will be a bitmap stored in memory ? But why ?

My sample is an extreme case, which is not really my productive App, so please don't ask why are you doing this. Its only an extreme case for trying to understand, what is going on.

mcfly soft
  • 11,289
  • 26
  • 98
  • 202

1 Answers1

2

The reason why it is consuming too much memory is obvious as its dimension is quite huge. To quote documentation-

In iOS 2.x, the maximum size of a UIView object is 1024 x 1024 points. In iOS 3.0 and later, views are no longer restricted to this maximum size but are still limited by the amount of memory they consume. It is in your best interests to keep view sizes as small as possible. Regardless of which version of iOS is running, you should consider tiling any content that is significantly larger than the dimensions of the screen.

Shripada
  • 6,296
  • 1
  • 30
  • 30
  • But I try to understand why it is consuming that much memory. Of course I should reduce the size to fit. It is an extreme sample what I described. I like to understand, what is the reason for. Is it a bitmap stored in the memory ? Or what ? And is this really true, that when I am drawing a simple text, that it produces a bitmap in the end. I guess this would be missdesign from Apple if a CALayer, which has a lot of advantages results as a bitmap in the end. – mcfly soft Jan 22 '16 at 10:46
  • And you are doing a transition animation, and remember, there is a presentation layer involved during animation and all this is going to cause huge surge in memory. – Shripada Jan 22 '16 at 10:59
  • No I am not doing any animations. I just translate the UIView with its calayers in it. – mcfly soft Jan 22 '16 at 11:05
  • Transitions are another type of animations only. So you still have all the load of an ordinary animation. – Shripada Jan 22 '16 at 11:09
  • But is the statement true, that the CATextlayer is stored as a bitmap, even 90% of the space is empty in case of a black text in empty background ? – mcfly soft Jan 22 '16 at 11:26