显示 NSPlaceholderstring 泄漏的仪器
我正在尝试减少应用程序中的内存泄漏,因此我使用仪器来查找所有泄漏。我设法消除了几乎所有的泄漏,除了一个非常烦人的泄漏。
Instruments 告诉我,我有很多 NSPlaceholderstring 泄漏。 生成泄漏的代码(根据仪器)是:
if (nil == storedHash)
{
NSString *description = [[NSString alloc] initWithFormat:@"1 = %@ 2= %d", uId, service];
self.storedHash = description; // This line is the leak according to instruments
[description release];
description = nil;
}
return storedHash
storedHash 的定义如下:
@property(copy) NSString* storedHash;
我尝试了我能想到的一切:
- 我使用保留而不是复制
- 我使用了 NSString(stringWithFormat)的自动释放分配
- 我尝试用以下代码包装代码自动释放池
以上都没有改变泄漏。 (在某些情况下,泄漏的类型会发生变化,但仍然存在泄漏)
有人有想法吗?
I'm trying to reduce the memory leaks in my app, so i used instruments to find all the leaks. I managed to remove almost all of the leaks, except a very annoying one.
Instruments is telling me that i have a lot of NSPlaceholderstring leaks.
The code that generated the leak (according to instruments) is:
if (nil == storedHash)
{
NSString *description = [[NSString alloc] initWithFormat:@"1 = %@ 2= %d", uId, service];
self.storedHash = description; // This line is the leak according to instruments
[description release];
description = nil;
}
return storedHash
storedHash is define like this:
@property(copy) NSString* storedHash;
I tried everything i can think of:
- I used retain instead of copy
- I used an autorelease allocation of the NSString (stringWithFormat)
- I tried wrapping the code with an autorelease pool
Nothing of the above changed the leak. (In some cases the type of the leaks change, but there are still leaks)
Ideas anyone?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
在哪里释放
storedHash
?你在dealloc
中释放它吗?请注意,
NSPlaceholdeString
是一个实现细节;它是NSString
的+alloc
方法返回的实例的类。Where do you release
storedHash
? Do you release it indealloc
?Note that
NSPlaceholdeString
is an implementation detail; it is the class of the instance returned byNSString
's+alloc
method.在
dealloc
方法中怎么样?你在dealloc方法中释放了storedHash吗?那么如何检查if (nil == self.storedHash)
How about in the
dealloc
method? Did you release the storedHash in the dealloc method? And how about checkingif (nil == self.storedHash)
您应该使用
复制来代替。
@property(copy)
没有释放你的旧 NSObject,你应该自己做:你也应该在 dealloc 中释放storedHash。
You should use
instead copy.
@property(copy)
didn't release your old NSObject and you should do it yourself:also you should release storedHash in dealloc.