NSString stringWithUTF8String中的内存泄漏 [英] Memory leak in NSString stringWithUTF8String

查看:1082
本文介绍了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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆