卤煮刚被web大潮淘汰到ios,当听说写oc要手动释放内存的时候如丧考妣,不过幸运的是ARC来了,妈妈再也不用担心我内存泄漏了。不过根据卤煮多年开发经验,和内存相关的不可能没有坑,开心之余还是得了解下oc是怎么搞内存的。
[TOC]
OC对象都有一个属性 retainCount 表明这个对象还有几个引用, 当retainCount为0, 说明这个对象没人用了,runtime就会回收掉。而所谓的内存泄漏就是明明没人用了,retainCount却不是0,runtime没有回收掉这个对象。
| /** | |
| * Created with IntelliJ IDEA. | |
| * User: ted | |
| * Date: 13-6-9 | |
| * Time: 下午3:59 | |
| * To change this template use File | Settings | File Templates. | |
| */ | |
| // copy from canjs | |
| // 把正则的敏感词转起来 |
| ioPool |
| #!/usr/bin/env node | |
| var fs = require('fs'); | |
| var root = process.argv[2] || __dirname; | |
| var reg = /#import "(.*?.).h"/; | |
| function getAllFiles() { | |
| var dictionaries = {}; | |
| var files = fs.readdirSync(root); | |
| files.forEach(function (dictionary) { |
| #!/usr/bin/env node | |
| var stdin = process.stdin, | |
| stdout = process.stdout; | |
| inputChunks = []; | |
| var reg = /(.*?)\s?=?\s?@\{([\s\S]*)\}/; | |
| stdin.resume(); | |
| stdin.setEncoding('utf8'); |
前段时间我在做一个代码重构的项目中发现一个Xcode奇怪的bug,我们往静态库里面加入了2000多个Objcetive C的class(工具生成),每个class一对.h.m文件,编译时XCode报错:
Verify final result code for completed build operation
Build operation failed without specifying any errors. Individual build tasks may have failed for unknown reasons. Some of these (up to 12) may be listed below.
| # Uncrustify 0.60 | |
| newlines = auto | |
| input_tab_size = 4 | |
| output_tab_size = 4 | |
| string_escape_char = 92 | |
| string_escape_char2 = 0 | |
| tok_split_gte = false | |
| utf8_bom = ignore | |
| utf8_byte = false | |
| utf8_force = false |