iPhone:从数据库读取循环中的数据时发生内存泄漏 [英] iphone: memory leak while reading data in loop from datatbase
本文介绍了iPhone:从数据库读取循环中的数据时发生内存泄漏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有人可以帮我弄清楚为什么这段代码泄漏以及我们如何处理吗?
Can anybody help me out why this piece of code is leaking and how can we handle it?
const char *sqlStatement = "SELECT * FROM VIOLATIONS_TBL";
sqlite3_stmt *compiledStatement;
if (sqlite3_prepare(database, sqlStatement, -1, &compiledStatement, NULL) == SQLITE_OK) {
while (sqlite3_step(compiledStatement) == SQLITE_ROW) {
NSString *recSTR=[[NSString alloc] initWithUTF8String:(char *)sqlite3_column_text(compiledStatement, 1)];
[self.pickerList addObject:recSTR];
[recSTR release];
recSTR=nil;
}
}
recSTR在这种情况下正在泄漏,我已经尝试了下面提到的所有解决方案,但是没有一个起作用 提前感谢
recSTR is leaking in this case and I have tried all the below mentioned solutions but none worked Thanx in advance
推荐答案
如果您的循环运行了很多次,请使用自动释放池
If your loop is running for a huge number of times then use autorelease pool
循环{
NSAutoreleasePool * innerPool = [[NSAutoreleasePool alloc] init];
loop {
NSAutoreleasePool *innerPool = [[NSAutoreleasePool alloc] init];
...code goes here...
[innerPool release];
}
它可以帮助您防止内存泄漏
It might help you prevent memory leak
这篇关于iPhone:从数据库读取循环中的数据时发生内存泄漏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文