[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Question about memory management

From: Maxthon Chan
Subject: Re: Question about memory management
Date: Fri, 07 Jun 2013 14:29:43 +0800

Just asking, with ARC, is this a good choice on implementing singleton?

#import <Foundation/Foundation.h>
@interface Singleton : NSObject
+ (instancetype)defaultSingleton;
// …
extern Singleton *DefaultSingleton // Of course this is optional

// Singleton.m
Singleton *DefaultSingleton
@implementation Singleton
+ (instancetype)defaultSingleton
if (!DefaultSingleton)
DefaultSingleton = [[self alloc] init];
return DefaultSingleton;
// …

在 2013-6-7,上午1:31,Ivan Vučica <address@hidden> 写道:

It depends on how the object is used -- in this case (without looking at the code), it sounds like it's a typical singleton approach.

On Wed, Jun 5, 2013 at 8:07 AM, Germán Arias <address@hidden> wrote:
Thanks for the explanation. I knew about static variables with strings (like @"hello").
And that these don't should be released. But I did not know that this applies to
other objects.


On 2013-06-04 23:55:15 -0600 Graham Lee <address@hidden> wrote:

> That's returning a shared static instance of the GSComboWindow class, so it's
> expected that it isn't released. It's also outside of the NSComboBoxCell
> class, so as far as NSComboBoxCell instances are concerned, they should obey
> standard memory management rules:
> - if you got an object via +alloc, -copy or -new, you own it and should
> -release or -autorelease it later.
> - if you didn't, you don't own it unless you -retain it
> - if you did neither of these, don't -release or -autorelease it.
> NSComboBoxCell is consistent with these rules.
> Graham.

Gnustep-dev mailing list

Ivan Vučica - address@hidden

Gnustep-dev mailing list

reply via email to

[Prev in Thread] Current Thread [Next in Thread]