Re: NSAlert boxes ...


Alex Zavatone
 

Why are you making it autorelease?

Run your method, display and dispose of the alert and then while your app is still running click on the Memory Graph Debugger icon in the debug bar.  Look at your allocations and leaks to see if any object of an NSAlert class is still there.

This will tell you if it’s needed or not.

On Feb 16, 2020, at 7:17 AM, Peter Hudson via Groups.Io <Peter.hudson@...> wrote:

Hi There

I see from the docs that when you create an NSAlert that you should dispose of it yourself.
My code for creating a simple alert and using it looks like this :-


NSAlert *alert = [[[NSAlert alloc] init] autorelease];
alert.messageText = @:Some message or other”;
[alert addButtonWithTitle:@"Create category"];
[alert addButtonWithTitle:@"Cancel"];
       
NSModalResponse choice = [alert runModal];

Etc …..

Is the use of an autorelease here O.K. ?

It certainly seems to work …..



Peter


Join cocoa@apple-dev.groups.io to automatically receive all group messages.