NSString stringWithUTF8String 中的内存泄漏 [英] Memory leak in NSString stringWithUTF8String
问题描述
我正在调用数据库.在我打电话之后,我发现 NSString 中存在泄漏.有没有人有办法删除它?
I am making a call to a database. After my call, I've found leaks in NSString. Anybody have a solution to remove it?
NSString *pic = [NSString stringWithUTF8String:(char *)sqlite3_column_text(selectStatement, 5)];
在上面的代码中,我发现了 90% 的泄漏.我只是从数据库中读取数据.
In above code, I found 90% leaks. I just read data from database.
推荐答案
请把问题解释清楚,否则其他人无法确定您的确切问题.
please explain the question well else others can't identify your exact problem.
我认为您正在将 [NSString stringWithUTF8String:(char *)sqlite3_column_text(selectStatement, 5)]; 的值分配给您的类对象属性.
I think you are you are assigning the value of [NSString stringWithUTF8String:(char *)sqlite3_column_text(selectStatement, 5)]; to your class object property.
可以在对应的类dealloc方法中释放分配的类字符串属性,也可以设置为nil.
You can release the assigned class string property in the corresponding class dealloc method.Also set it nil.
示例:
如果你在做
YourClass *classObj =[ YourClass alloc] init];
classObj.myStringvariable = [NSString stringWithUTF8String:(char *)sqlite3_column_text(selectStatement, 5)];
类结构会喜欢
@interface YourClass {
NSString *myStringvariable ;
}
@property (nonatomic,retain) NSString *myStringvariable ;
.m 文件将是
@synthesise myStringvariable ;
-(void)init{
myStringvariable = @"";
}
-(void)dealloc{
[myStringvariable release];
myStringvariable = nil;
}
检查一下..这个结构不会显示内存泄漏.
Check it.. this structure will not show memory leak.
这篇关于NSString stringWithUTF8String 中的内存泄漏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!