开发者

How to release this object?

开发者 https://www.devze.com 2023-01-06 14:10 出处:网络
I have taken the MailComposer example added to a simple project and under a button I am executing the following code:

I have taken the MailComposer example added to a simple project and under a button I am executing the following code:

// display in app email
MailComposerViewController *emailClient = [[MailComposerViewController alloc] init];
[self.view addSubview:emailClient.view];
[emailClient showPicker:self];
[emailClient release];

Last line is give me headache. If I don't put that like I create a memory leak, if I add that line the mail client shows up but then the app hangs when I click cancel or send. With the memory leak (aka no last line) everything 开发者_Go百科works fine.

What is the best way in a very well know case like this? I want to create an option in the same method and that object has delegates and such. It's not worth to have that object alive for the entire life of the app.

Thanks, amok


You need to keep a view controller while you're using the view managed by the said view controller. Instead, you need to have an instance variable or a property in which you keep emailClient.

It's great that you want to use as small an amount of memory as possible; but sometimes it's just necessary to keep some objects alive.

0

精彩评论

暂无评论...
验证码 换一张
取 消