App crashes when adding several CALayers as subLayers inside my DrawRect

1

I am trying to add 43 layers as subLayers on top of my parentLayer. Here is how I create my CALayer:

_imgZutendaal = [CALayer layer];
_imgZutendaal.contents = (id)[imZutendaal CGImage];
_imgZutendaal.frame = CGRectMake(0, 0, 656, 608);

And this is how I add it to my parentLayer:

[self.layer addSublayer:_imgAchel];

But for some reason it crashes without any error messages. When I only add for example 10 subLayers everything works OK.

Can somebody help me ?

*EDIT *

My device LOG

Incident Identifier: 4BD67C7D-D47B-4C94-AD6B-FDD0E1F9B643
CrashReporter Key:   3591649072652267c2ffce5538acf9e3e735a8eb
Hardware Model:      iPad3,6
OS Version:          iPhone OS 6.1.3 (10B329)
Kernel Version:      Darwin Kernel Version 13.0.0: Wed Feb 13 21:40:39 PST 2013; root:xnu-2107.7.55.2.2~1/RELEASE_ARM_S5L8955X
Date:                2013-10-04 19:52:54 +0200
Time since snapshot: 195 ms

Free pages:        7861
Active pages:      23923
Inactive pages:    23223
Throttled pages:   173060
Purgeable pages:   1800
Wired pages:       22068
Largest process:   Architab

Processes
     Name                    <UUID>                       rpages       recent_max       [reason]          (state)

           timed <13d1143a8d7433cdbec64d4279aee1fe>          399              399                      (daemon) (idle)
    itunesstored <be14ada6a4d836f0aac6cf104f600c64>         1387             1387                      (daemon) (idle)
networkd_privile <20292830d8d53949b82495c145d0a379>          139              139                      (daemon) (idle)
            afcd <af436cb36cfe3eb0b98e588cc58b1125>          269              269                      (daemon) (idle)
        installd <4da1ba8fb7cd3c6690edf3e2a3c24269>          486              486                      (daemon) (idle)
coresymbolicatio <1ad086cff8bf3a268aa46add679eb35c>          145              145                      (daemon) (idle)
     Preferences <1146c082660137cabc87e26cdde5362c>         2278             2278                      (suspended)
softwareupdatese <1e626439b28f3e778f6a90c15b355c5d>          578              578                      (daemon) (idle)
             lsd <fe3afa7c718c30e591f1324f09d08c4f>          399              399                      (daemon) (idle)
AppleIDAuthAgent <d17fbf632e6b30448fbb7b6a0a2ea4d5>          256              256                      (daemon) (idle)
      MobileMail <aed39adc22ee334c90bca672f578f1c0>         1871             1871                      (continuous)
            tccd <e6dbe43518593da19ff55a9f3f15b3de>          191              191                      (daemon)
             kbd <47657f4dd979300a840367905786eccc>          799              799                      (daemon)
        Architab <0ca94fc340d83c29a7bca8e205ee1f55>       166401           166401  [per-process-limit] (frontmost) (resume)
            ptpd <e6aba1b273cc37839edb237a5100008a>         1162             1162                      (daemon)
         syslogd <42cd10099569364f811f66ad6f6dea46>          422              422                      (daemon)
   iaptransportd <30bda0eeebb73681939e4223845ff0de>          314              314                      (daemon)
       locationd <2d8cb2921fb538d4bb4aed62af98b4d2>         1161             1161                      (daemon)
        profiled <3511fda29f3e3cb3924bd46dbecd7e48>          708              708                      (daemon)
    mediaserverd <221fa80d17503fc7aa86f1041bdcc0be>         1473             1473                      (daemon)
     dataaccessd <7b294c10f04f36af8086f4ccb5606fae>         1037             1037                      (daemon)
           wifid <71a35a9968a4358a8569e6de843ad1aa>          509              509                      (daemon)
     SpringBoard <b0713272db793942ac49d8d3c84c2c2e>         8733             8733                     
      backboardd <d9997ef1b2bc3015862615abf37ebb1b>        12221            12221                      (daemon)
  UserEventAgent <d19ebe160ed536c8b18c89f066b758a6>          759              759                      (daemon)
     debugserver <3b87b63ad5bd3936aaee48b6c806a648>            0                0                      (daemon)
springboardservi <6bd52da73e793cf8bf9faa33d0df0de9>            0                0                      (daemon)
   syncdefaultsd <9c9a6da6f6993bb2be6ba01b851dc3e9>          463              463                      (daemon)
        sandboxd <bbb7e05047a937159530525e2657928a>          290              290                      (daemon)
         lockbot <721e765c832334ce9365174aa595916f>         1293             1293                      (daemon)
    syslog_relay <d81c4c84d1b83c3696ac492acabfb7ad>            0                0                      (daemon)
mobile_assertion <721ceb33d66a3dd1a2f599202a73402b>          297              297                      (daemon)
notification_pro <9f20f84f20893071ace566277995152e>          279              279                      (daemon)
            afcd <af436cb36cfe3eb0b98e588cc58b1125>          268              268                      (daemon)
filecoordination <44b0075fbc5b3af5b403fc3bcb6603b0>          201              201                      (daemon)
       distnoted <4b2b2984057b3df2a7e5c7d1d79a099b>          148              148                      (daemon)
            apsd <9ba45b14c44d340da1c3a41f28b46f65>          320              320                      (daemon)
        networkd <26c89c34e3e031fdb46bea7bed9df0ff>          268              268                      (daemon)
      aggregated <a2d209b4577a3697a10c288fd542e501>          121              121                      (daemon)
       fseventsd <b148ac55dd67325e822695755023a16e>          463              463                      (daemon)
        BTServer <e6eb89b2fe7b3b219a2d90e6735b166d>          534              534                      (daemon)
         imagent <e61401f9f6303ae189c517add142b837>          388              388                      (daemon)
         configd <d2cd8bc6ed643fa69392c80fc416cd8b>          621              621                      (daemon)
       lockdownd <f960236277c33ac78488eeea78661347>          518              518                      (daemon)
          powerd <fde6e83ab5f63bfeb5313e4cd86b25cc>          221              221                      (daemon)
  fairplayd.P103 <6a887996d5ad307b85f22f4821fa1f1e>          625              625                      (daemon)
   mDNSResponder <b9aedd3c47f43627af9b55c3d0844f16>          366              366                      (daemon)
      CommCenter <3fbedab9761b3733a3fc0cd58ab00055>         1813             1813                      (daemon)
         notifyd <bbd1f04dd7163c93bc9eb6e5a7b14ab7>          183              183                      (daemon)

**End**

And this is what I get when I look at the device console

Oct  4 19:55:25 iPad UserEventAgent[13] <Notice>: jetsam: kernel termination snapshot being created
Oct  4 19:55:25 iPad com.apple.launchd[1] (UIKitApplication:com.appmax.Architab[0xbd7][6951]) <Notice>: (UIKitApplication:com.appmax.Architab[0xbd7]) Exited: Killed: 9
Oct  4 19:55:25 iPad com.apple.debugserver-199[6949] <Warning>: 1 +0.000000 sec [1b25/1303]: error: ::read ( 5, 0x1349fc, 18446744069414585344 ) => -1 err = Bad file descriptor (0x00000009)
Oct  4 19:55:25 iPad backboardd[26] <Warning>: Application 'UIKitApplication:com.appmax.Architab[0xbd7]' exited abnormally with signal 9: Killed: 9
Oct  4 19:55:25 iPad ReportCrash[6952] <Error>: libMobileGestalt copySystemVersionDictionaryValue: Could not lookup ReleaseType from system version dictionary
Oct  4 19:55:25 iPad ReportCrash[6952] <Notice>: Saved crashreport to /Library/Logs/CrashReporter/LowMemory-2013-10-04-195525.plist using uid: 0 gid: 0, synthetic_euid: 0 egid: 0
iphone
ios
objective-c
calayer
drawrect
asked on Stack Overflow Oct 4, 2013 by Steaphann • edited Oct 4, 2013 by Steaphann

1 Answer

3

Your app runs out of memory. The crash reports indicates that your app uses 166401 pages of memory, i.e. 650 MByte. For that reason it's killed.

Your layers are most likely the main cause of the memory problem. The memory consumption of a single layer will depend on its contents, i.e. on the image you assign. If the image is 600 by 600 pixels, then it will at least consume 1 MByte (600 x 600 x 3).

Use Instruments to profile your app for memory usage. Find out why and where the memory usage increases. Possibly the memory usage is already very high before you start adding the layers. Or you add the same layer several times.

answered on Stack Overflow Oct 4, 2013 by Codo

User contributions licensed under CC BY-SA 3.0