d-squared
d-squared

Reputation: 107

How much memory does an empty CALayer consume?

I have created an instance of CALayer using [CALayer layer] and set its frame to the frame of the screen (e.g. 768 by 1024 points). I have not set the contents of this layer. Will this layer take up extra memory because of the larger size, or does the memory consumption remain the same because it has nothing to draw?

Upvotes: 1

Views: 1014

Answers (3)

mojuba
mojuba

Reputation: 12237

I just measured it by allocating a large number of empty CALayer's, looks like each takes about 340 bytes of memory. Assigning some ridiculously large frames doesn't change it even a bit.

Layers, however, can consume significant amount of memory and not only because of the image contents, but also due to internal pixel caching it seems. I haven't experimented with this yet, but pretty sure even shape or text layers aren't that small once they start drawing on the screen.

Upvotes: 1

Florian
Florian

Reputation: 100

A CALayer basically is just a few properties and methods. So the CALayer itself (almost) doesn't cost memory. If you assign an Image to the contents-property of course then this will cost the amount of memory your Image uses in decompressed (CGImage) form.

(Afaik the CALayer only stores an reference to the actual Image so to be precise the CALayer itself still has almost no memory usage)

To check the memory-usage of your App at runtime use the (very cool) Profiling-Tool:

  1. Build for Profiling
  2. Under run, choose Profile
  3. Choose "Memory usage" (or similar, I'm not sitting at my MAC right now)
  4. Click the red "record"-button on the top-left

enjoy

Upvotes: 3

Ulaş Sancak
Ulaş Sancak

Reputation: 907

If you want, you can check the free memory before and after create the layer. If you want to do that please check this:

Determining the available amount of RAM on an iOS device

Upvotes: 0

Related Questions