为什么这段代码会泄露? (iPhone)

发布于 2024-09-02 01:55:49 字数 788 浏览 4 评论 0原文

这是标题:(

@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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

舞袖。长 2024-09-09 01:55:49

你不应该在你正在做的地方释放它,而是将释放移动到 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 ?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文