Re: Question about memory management

2013-06-07 Thread Maxthon Chan
Just asking, with ARC, is this a good choice on implementing singleton? //Singleton.h #import Foundation/Foundation.h @interface Singleton : NSObject + (instancetype)defaultSingleton; // … @end extern Singleton *DefaultSingleton // Of course this is optional // Singleton.m Singleton

Re: Question about memory management

2013-06-07 Thread David Chisnall
On 7 Jun 2013, at 07:29, Maxthon Chan xcvi...@me.com wrote: Just asking, with ARC, is this a good choice on implementing singleton? No, it's not thread-safe. //Singleton.h #import Foundation/Foundation.h @interface Singleton : NSObject + (instancetype)defaultSingleton; // … @end extern

Re: Question about memory management

2013-06-07 Thread Graham Lee
On 7 Jun 2013, at 09:26, David Chisnall david.chisn...@cl.cam.ac.uk wrote: My preferred pattern is: + (void)initialize { [[self alloc] init]; } Should this be wrapped in if(self == [Singleton class])? I've seen that used to guard against this +initialize being called multiple times

Re: Question about memory management

2013-06-07 Thread Maxthon Chan
I don't want an exclusive singleton - that is, there is not only one shared singleton instance, the user can also set up one for their own, like recent versions of NSFileManager on OS X. Can I do this: // Singleton.m static Singleton *__singleton @implementation Singleton +

Re: Question about memory management

2013-06-07 Thread David Chisnall
On 7 Jun 2013, at 09:30, Graham Lee gra...@iamleeg.com wrote: Should this be wrapped in if(self == [Singleton class])? I've seen that used to guard against this +initialize being called multiple times when a subclass is used that doesn't override the method. Good catch. The answer is...

Re: Question about memory management

2013-06-07 Thread Maxthon Chan
Well can I (just like NSApplication): 1) In supercalss, define the shared instance as id 2) In superclass, return the shared instance as id or instancetype 3) In superclass, DO NOT set up yet. 4) In superclass, set up in the method asking for the shared instance, which always use [[self alloc]

Re: Question about memory management

2013-06-07 Thread David Chisnall
On 7 Jun 2013, at 09:34, Maxthon Chan xcvi...@me.com wrote: I don't want an exclusive singleton - that is, there is not only one shared singleton instance Exclusive singleton is a tautology. By definition, singletons are exclusive. , the user can also set up one for their own, like recent

Re: Question about memory management

2013-06-07 Thread David Chisnall
On 7 Jun 2013, at 09:42, Maxthon Chan xcvi...@me.com wrote: Well can I (just like NSApplication): 1) In supercalss, define the shared instance as id 2) In superclass, return the shared instance as id or instancetype 3) In superclass, DO NOT set up yet. 4) In superclass, set up in the

Re: Question about memory management

2013-06-07 Thread Ivan Vučica
On 7. 6. 2013., at 10:47, David Chisnall thera...@sucs.org wrote: On 7 Jun 2013, at 09:42, Maxthon Chan xcvi...@me.com wrote: Well can I (just like NSApplication): 1) In supercalss, define the shared instance as id 2) In superclass, return the shared instance as id or instancetype 3) In

Re: Question about memory management

2013-06-06 Thread Ivan Vučica
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 ger...@xelalug.org wrote: Thanks for the explanation. I knew about static variables with strings (like @hello).

Re: Question about memory management

2013-06-05 Thread Germán Arias
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. Thanks. Germán. On 2013-06-04 23:55:15 -0600 Graham Lee gra...@iamleeg.com wrote: That's returning a shared

Re: Question about memory management

2013-06-04 Thread Graham Lee
NSComboBoxCell doesn't release its popup window, but it doesn't retain it either so there's no unbalanced memory use. Graham. On 4 Jun 2013, at 00:33, Germán Arias ger...@xelalug.org wrote: For autocomplete I have a class GSAutocompleteWIndow. The method -complete: (in NSTextVIew) do

Re: Question about memory management

2013-06-04 Thread Germán Arias
On 2013-06-03 23:59:15 -0600 Graham Lee gra...@iamleeg.com wrote: NSComboBoxCell doesn't release its popup window, but it doesn't retain it either so there's no unbalanced memory use. Graham. Well, isn't retained. But is created with +alloc and -init. And since this is a panel, this

Re: Question about memory management

2013-06-04 Thread Graham Lee
Where are you seeing that? I'm looking at -_popUp here: http://svn.gna.org/svn/gnustep/libs/gui/trunk/Source/NSComboBoxCell.m No -init, -new or -copy that I can see. Graham. On 5 Jun 2013, at 00:30, Germán Arias ger...@xelalug.org wrote: On 2013-06-03 23:59:15 -0600 Graham Lee

Re: Question about memory management

2013-06-04 Thread Germán Arias
Class method +defaultPopUp, line 118. Germán. On 2013-06-04 23:38:10 -0600 Graham Lee gra...@iamleeg.com wrote: Where are you seeing that? I'm looking at -_popUp here: http://svn.gna.org/svn/gnustep/libs/gui/trunk/Source/NSComboBoxCell.m No -init, -new or -copy that I can see. Graham.

Re: Question about memory management

2013-06-04 Thread Graham Lee
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

Question about memory management

2013-06-03 Thread Germán Arias
For autocomplete I have a class GSAutocompleteWIndow. The method -complete: (in NSTextVIew) do something like: GSAutocompleteWindow *window = [GSAutocompleteWindow defaultWindow]; [window displayForTextView: self]; I think I should release this window at some point. Maybe in -dealloc or with a

Re: Question about memory management

2013-06-03 Thread Maxthon Chan
Can you compile it with -fobjc-arc and check again? Probably with ARC you can have some ideas. 在 2013-6-4,上午7:33,Germán Arias ger...@xelalug.org 写道: For autocomplete I have a class GSAutocompleteWIndow. The method -complete: (in NSTextVIew) do something like: GSAutocompleteWindow *window =

Re: Question about memory management

2013-06-03 Thread Ivan Vučica
On 4. 6. 2013., at 02:14, Maxthon Chan xcvi...@me.com wrote: Can you compile it with -fobjc-arc and check again? Probably with ARC you can have some ideas. When you're not sure how something is memory managed, compiling with ARC is probably a terrible idea. Turning magic into

Re: Question about memory management

2013-06-03 Thread Maxthon Chan
A side note about autocomplete, I always cross-develop GNUstep apps under OS X, just for that Xcode capabilities. I really should build a GNUstep/Linux toolchain and SDK for Xcode to use so that at least before ProjectCenter and Gorm is in good shape we can develop using Xcode on OS X and copy

Re: Question about memory management

2013-06-03 Thread Germán Arias
On 2013-06-03 18:58:39 -0600 Ivan Vučica ivuc...@gmail.com wrote: The method is named +defaultWindow; it does not include alloc, create, new; hence its retaincount is +1 (-1), which is how I denote currently 1, but autoreleased once. This method includes +alloc and -init. But what confuses