Search code examples
objective-cioscalayer

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?


Solution

  • 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