2013-10-04 272 views
1

裏面我想在我的parentLayer的頂部添加43層爲subLayers。這是我如何創建我CALayer應用程序崩潰時我的drawRect

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

這是我怎麼把它添加到我的parentLayer:

[self.layer addSublayer:_imgAchel]; 

但由於某些原因崩潰沒有任何錯誤消息。當我只添加例如10個子層時,一切正常。

有人能幫助我嗎?

* 編輯*

我的設備日誌

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** 

這是當我看設備控制檯

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 
+2

你真的說你正在改變UIView的'drawRect:'方法中的子層嗎?那肯定會遇到麻煩。 – Codo

+0

那我應該怎麼做呢? – Steaphann

+0

這取決於您的應用程序:如果始終需要圖層,請將其添加到'viewDidLoad'中。如果在某些用戶操作後需要它們,請將其添加到手勢識別器的操作方法中。如果在從服務器收到一些數據後需要它們,請將它們添加到'connectionDidFinishLoading:'中。 – Codo

回答

3

您的應用程序運行的內存是我所得到。崩潰報告表明您的應用程序使用166401頁的內存,即650 MByte。因爲這個原因它被殺了。

您層最有可能的內存問題的主要原因。單層的內存消耗將取決於其內容,即取決於您分配的映像。如果圖像是600 x 600像素,那麼它至少會消耗1 MB(600 x 600 x 3)。

使用工具來分析您的應用程序的內存使用情況。瞭解內存使用量增加的原因和位置。在開始添加圖層之前,內存使用情況可能已經非常高。或者你多次添加同一個圖層。

+0

如何查看導致內存增加的原因? – Steaphann

+1

運行*儀器* *分配*分析。然後觀察頂部的儀表。您會立即發現應用程序中的操作會導致內存使用量急劇增加。然後,您可以使用*標記生成*按鈕在記憶增加之前和之後設置標記。然後,您可以檢查相關的快照生成,以確定哪些實例導致增加。最初還要觀察* Live Bytes *以確保啓動後內存使用率尚未達到最高。 – Codo