看板 MacDev 關於我們 聯絡資訊
我想要在程式裡連續製作多張UIImage 我用了以下方法 -(void)creatImage { UIImage *image; UIGraphicsBeginImageContextWithOptions(newSize, NO, 0); ... ...(中間使用drawInRect畫圖) @autoreleasepool { image = UIGraphicsGetImageFromCurrentImageContext(); [images addObject:image]; // images是個array,用來裝做好的UIImage image = nil; } UIGraphicsEndImageContext(); } 接著我用for迴圈去跑creatImage這個method 只跑2次的話,沒什麼問題,可是如果設定16次 當他跑到第7次左右的時候就crash了,沒有顯示錯誤在哪 網路上查的結果應該是UIGraphicsGetImageFromCurrentImageContext造成了memory的問題 我照其他人的做法加了@autoreleasepool,結果還是crash (http://goo.gl/ibrbte) 有人知道該怎麼解決這個問題嗎? -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 140.112.218.72 ※ 文章網址: https://www.ptt.cc/bbs/MacDev/M.1431677583.A.6BB.html
darktt: 試試看將圖片寫入cache的資料夾下再將圖片透過路徑讀入 05/15 16:37
darktt: 放棄原本的image的instance的方法 05/15 16:38
howdiun: 沒有顯示錯誤在哪就應該不是memory的問題 05/15 16:38
y03131003: 我是跳出lost connection視窗 http://goo.gl/GS6qEm 05/15 16:43
y03131003: 連結裡說應該是memory的問題 05/15 16:43
y03131003: 我將[images addObject:image]註解掉 就不會crash了!!! 05/15 16:44
y03131003: 我試試看寫入cache的方法! 05/15 16:45
y03131003: 找到問題了!從Context得到的圖片檔案超大11MB.. 05/15 17:31
y03131003: 我先壓縮成0.01倍存到cache資料夾再透過路徑讀入就搞定 05/15 17:31
y03131003: 感謝各位~~ 05/15 17:33