Iphone 如何解决内存泄漏问题?

Iphone 如何解决内存泄漏问题?,iphone,Iphone,我正在开发一个应用程序,在该应用程序中,我发现内存泄漏,请按照下面的方法执行操作:如何消除泄漏 - (id)initWithString:(NSString *)str attributes:(NSDictionary *)attributes { if ((self = [super init])) { _buffer = [str mutableCopy]; _attributes = [NSMutableArray arrayWithObj

我正在开发一个应用程序,在该应用程序中,我发现内存泄漏,请按照下面的方法执行操作:如何消除泄漏

- (id)initWithString:(NSString *)str attributes:(NSDictionary *)attributes
{

    if ((self = [super init]))
    {
        _buffer = [str mutableCopy];
        _attributes = [NSMutableArray arrayWithObjects:[ZAttributeRun attributeRunWithIndex:0 attributes:attributes], nil];
    }

    return self;

}
我在这行附近找到了“\u buffer=[str mutableCopy]

在分配堆栈跟踪中,我发现同步内存分配以CFString的形式增加


谢谢

mutableCopy保留返回的对象,因此您有责任在处理完后释放它。这符合。

我认为如果在
dealloc
方法中放置一行
[\u缓冲区释放]
,则不会出现内存泄漏。您有一个分配,因为对于每个包含
alloc
retain
copy
等内容的方法。。。创建一个新的对象实例。在这种情况下没关系


您必须担心的另一件事是
\u属性
对象的内存崩溃。您拥有一个自动释放的对象,下次尝试使用它时,它可能已被释放

请更小心地格式化您的代码。你的一点努力有助于我们帮助你。