共享委托上的内存泄漏
我正在使用共享委托来获取有关 URL 连接的数据。我的代码出现内存泄漏。有人可以告诉我我做错了什么吗?
分析仪警告:
/Users/sathish/Documents/XXX 20100908 ManageMem/Classes/Data Download/XXX DataConnect.m:68:22:警告:第 68 行分配的对象存在潜在泄漏 gXXXDataConnect = [[XXXDataConnect alloc] customInit] ;
XXXDataConnect.h
- (XXXDataConnect*)sharedXXXDataConnect;
XXXDataConnect.m
- (XXXDataConnect *)sharedXXXDataConnect { if(gXXXDataConnect == nil) gXXXDataConnect = [[XXXDataConnect alloc] customInit] ; 返回 gXXXDataConnect ; }
I am using shared delegate for getting data on URL connection. I'm getting a memory leak on my code. Can anybody please tell me what I have done wrong?
Analyser Warning:
/Users/sathish/Documents/XXX 20100908 ManageMem/Classes/Data Download/XXX DataConnect.m:68:22: warning: Potential leak of an object allocated on line 68
gXXXDataConnect = [[XXXDataConnect alloc] customInit] ;
XXXDataConnect.h
- (XXXDataConnect*)sharedXXXDataConnect;
XXXDataConnect.m
- (XXXDataConnect *)sharedXXXDataConnect
{
if(gXXXDataConnect == nil)
gXXXDataConnect = [[XXXDataConnect alloc] customInit] ;
return gXXXDataConnect ;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
好吧,您永远不会释放刚刚分配的 XXXDataConnect。如果你不取消分配,谁会取消分配?
假设这是 Objective-C,我认为您需要一个
return [gXXXDataConnect autorelease]
作为函数结束。 http://www.otierney.net/objective-c.html#retain 这里可能是一个有用的链接。Well, you're never deallocating your XXXDataConnect you've just allocated. If you don't deallocate it, who will?
Assuming this is Objective-C, I think you need a
return [gXXXDataConnect autorelease]
as your end-of-function. http://www.otierney.net/objective-c.html#retain might be a helpful link here.