为什么这段代码会泄露? (iPhone)
这是标题:(
@interface ForumBrowserAppDelegate : NSObject <UIApplicationDelegate> {
ForumSelection *forumSelection;
UIWindow *window;
}
@property (nonatomic, retain) IBOutlet UIWindow *window;
@property (nonatomic, retain) IBOutlet ForumSelection *forumSelection;
我不确定非原子的作用是什么,它与多线程安全有关吗,我真的需要它吗?)
在主文件中:
- (void)applicationDidFinishLaunching:(UIApplication *)application {
// Override point for customization after app launch
[window addSubview:forumSelection.view]; //<<<< Instruments highlights this line
[forumSelection release];
[window makeKeyAndVisible];
}
最初我没有属性在标题或 [forumSelection release];
所以我认为这可能是它泄漏的原因,但是 Instruments 仍然说这个泄漏,我不知道为什么?
This is the header:
@interface ForumBrowserAppDelegate : NSObject <UIApplicationDelegate> {
ForumSelection *forumSelection;
UIWindow *window;
}
@property (nonatomic, retain) IBOutlet UIWindow *window;
@property (nonatomic, retain) IBOutlet ForumSelection *forumSelection;
(I'm not sure what the nonatomic does, is it something to do with making it safe with multiple threads, do i really need it?)
In the main file:
- (void)applicationDidFinishLaunching:(UIApplication *)application {
// Override point for customization after app launch
[window addSubview:forumSelection.view]; //<<<< Instruments highlights this line
[forumSelection release];
[window makeKeyAndVisible];
}
Originally I didn't have the property thing in the header or the [forumSelection release];
So I thought that might be why it leaks however Instruments still says this leaks and I have no idea why?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你不应该在你正在做的地方释放它,而是将释放移动到 dealloc - 它不是“你的”要释放的 - 它是从 XIB 中解压出来的。不解释泄漏。
您确定泄漏不在 forumSelection 中吗?
you should not release it where you are doing, instead move the release to dealloc - its not "yours" to release - it was unpacked from the XIB. Doesn't explain the leak.
Are you sure the leak is not in forumSelection ?