内存问题:
使用xcode4.02自带的Instruments测试工具检测代码时发现执行同一段代码有时会查出内存泄漏,有时又查不出,这是为何?是否项目通过Instruments的检测就代表该项目绝对不会在运行时出现内存溢出,还是说Instruments只能做到静态的分析代码,指出代码编写上的明显问题?该段随机检出内存异常的代码段如下:- (UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}
NSString *cellText = [NSString stringWithFormat:@"音频文件%d",(indexPath.row +1)]; //内存溢出
cell.textLabel.text = cellText;
if ([cellText isEqualToString:selectText]) {
cell.accessoryType = UITableViewCellAccessoryCheck;
thisIndexPath = indexPath;
}
return cell;
}异常问题:
如何为一个方法声明异常,从而使该方法的调用者必须在编译期为其套上try-catch?(类似于java或C#的void funcName(Param1 param1) throws MyException)为何ios平台应用不建议我们使用异常?另:
xcode4.02如何开启僵尸及其日志?----------------------
问题多了点,还请各位前辈帮助下晚辈,在此先谢谢大家了。
使用xcode4.02自带的Instruments测试工具检测代码时发现执行同一段代码有时会查出内存泄漏,有时又查不出,这是为何?是否项目通过Instruments的检测就代表该项目绝对不会在运行时出现内存溢出,还是说Instruments只能做到静态的分析代码,指出代码编写上的明显问题?该段随机检出内存异常的代码段如下:- (UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}
NSString *cellText = [NSString stringWithFormat:@"音频文件%d",(indexPath.row +1)]; //内存溢出
cell.textLabel.text = cellText;
if ([cellText isEqualToString:selectText]) {
cell.accessoryType = UITableViewCellAccessoryCheck;
thisIndexPath = indexPath;
}
return cell;
}异常问题:
如何为一个方法声明异常,从而使该方法的调用者必须在编译期为其套上try-catch?(类似于java或C#的void funcName(Param1 param1) throws MyException)为何ios平台应用不建议我们使用异常?另:
xcode4.02如何开启僵尸及其日志?----------------------
问题多了点,还请各位前辈帮助下晚辈,在此先谢谢大家了。
所以自然IOS没有必要学不好的东西。
C/C++的异常处理很好的可以在IOS下工作。
关于开启僵尸和日志。
你可以在项目的Edit SCHEMA和Build的一些设置中修改和开启。
方法一,添加环境变量, 在菜单中,选择Product->Edit Schema, 选择Run (App Name), 在Arguments下面的Environment Variables中,添加NSZombieEnabled, Value值为YES。
方法二,打开Diagnostics, 同样在菜单中选择Product -> Edit Schema, 选择Run (App Name), 在Diagnostics下,打开Memory Management下的Enable Zombie Objects
方法二Memory Management下没有Enable Zombie Objects勾选框。