 | | From: | Pierre Chatel | | Subject: | Cocoa GC ? | | Date: | Wed, 8 Dec 2004 23:29:23 -0500 |
|
|
 | Is there a garbage collector implementation for Cocoa (i heard that it was impossible due to refcounting memory management in cocoa). What about Boehm ?
Pierre CHATEL
|
|
 | | From: | Michael Ash | | Subject: | Re: Cocoa GC ? | | Date: | Thu, 09 Dec 2004 01:11:57 -0600 |
|
|
 | Pierre Chatel wrote: > Is there a garbage collector implementation for Cocoa (i heard that it > was impossible due to refcounting memory management in cocoa). What > about Boehm ?
ObjC has the same limitations as C does as far as garbage collectors go, but boehm is there and it works. GNUStep has the option of using boehm, so it's obviously possible.
Cocoa has some architectural limitations that would need to be addressed before it could use boehm. For example, a great deal of code signs up for notifications with NSNotificationCenter, and removes itself from the notification in the -dealloc method. While this works fine with manual reference counting, since NSNotificationCenter doesn't retain its clients, a garbage collector would see that the object still has a live reference and would not collect it, turning it into a chicken-and-egg situation. NSNotificationCenter and any other object that relies on -dealloc to clear a reference would have to be modified to use weak references, which would be particularly hard to do given that Cocoa is not open source.
|
|
 | | From: | Pierre Chatel | | Subject: | Re: Cocoa GC ? | | Date: | Thu, 9 Dec 2004 13:27:13 -0500 |
|
|
 | On 2004-12-09 02:11:57 -0500, Michael Ash said:
> Pierre Chatel wrote: >> Is there a garbage collector implementation for Cocoa (i heard that it >> was impossible due to refcounting memory management in cocoa). What >> about Boehm ? > > ObjC has the same limitations as C does as far as garbage collectors > go, but boehm is there and it works. GNUStep has the option of using > boehm, so it's obviously possible. > > Cocoa has some architectural limitations that would need to be > addressed before it could use boehm. For example, a great deal of code > signs up for notifications with NSNotificationCenter, and removes > itself from the notification in the -dealloc method. While this works > fine with manual reference counting, since NSNotificationCenter doesn't > retain its clients, a garbage collector would see that the object still > has a live reference and would not collect it, turning it into a > chicken-and-egg situation. NSNotificationCenter and any other object > that relies on -dealloc to clear a reference would have to be modified > to use weak references, which would be particularly hard to do given > that Cocoa is not open source.
i see... i'm wondering how java's dealing with this notification model. Objects that registered themselves to a notifier (which is storing refs on arrays or such) would never be garbage collected, right ? Except if they dont explicitely de-register themselves. As far as i know u don't have access to a -dealloc equivalent in Java. So could u just add "categories" to cocoa classes with correct weak references in order for boehm to work... Maybe overiding doesn't work well in with categories
Maybe i'm just saying something silly :-) I'm sure doing... i'm kinda newbie with objC and cocoa in general.
Pierre
|
|
 | | From: | Gregory Weston | | Subject: | Re: Cocoa GC ? | | Date: | Thu, 09 Dec 2004 19:39:46 GMT |
|
|
 | In article <2004120913271316807%admin@chatelporg>, Pierre Chatel wrote:
> i see... i'm wondering how java's dealing with this notification model. > Objects that registered themselves to a notifier (which is storing refs > on arrays or such) would never be garbage collected, right ? Except if > they dont explicitely de-register themselves. As far as i know u don't > have access to a -dealloc equivalent in Java.
The nearest equivalent - and it isn't that far off, really - is finalize(). It's your chance to clean up any deferred activity, release native resources, etc.
G
-- Change account to gw when responding by mail.
|
|
 | | From: | David Stes | | Subject: | Re: Cocoa GC ? | | Date: | Thu, 09 Dec 2004 21:25:02 GMT |
|
|
 | Pierre Chatel wrote: > > i see... i'm wondering how java's dealing with this notification model.
I think it does not really depend on Java but rather on the libraries that you implement in that language.
If you write a library in Java that references all objects, then Java (the language) cannot release all these objects either.
|
|
 | | From: | Sherm Pendley | | Subject: | Re: Cocoa GC ? | | Date: | Thu, 09 Dec 2004 17:18:09 -0500 |
|
|
 | Pierre Chatel wrote:
> i'm kinda newbie with objC and cocoa in general.
With all due respect then, perhaps you should be focusing on learning Cocoa as it is, rather than trying to make it more like something else.
Take a step back - what problem did you encounter, that you thought that garbage collection would provide an answer to?
sherm--
-- Cocoa programming in Perl: http://camelbones.sourceforge.net Hire me! My resume: http://www.dot-app.org
|
|
 | | From: | Pierre Chatel | | Subject: | Re: Cocoa GC ? | | Date: | Thu, 9 Dec 2004 21:27:44 -0500 |
|
|
 | On 2004-12-09 17:18:09 -0500, Sherm Pendley said:
> Pierre Chatel wrote: > >> i'm kinda newbie with objC and cocoa in general. > > With all due respect then, perhaps you should be focusing on learning > Cocoa as it is, rather than trying to make it more like something else.
This is what i'm trying to do...
> > Take a step back - what problem did you encounter, that you thought > that garbage collection would provide an answer to?
none. In fact, if you had read the thread from the beginning you would have seen that it was just curiosity from myself. Yes i could just follow the simple programming patterns related to ref-counting memory management but i wanted a more "in-depth" look i was expecting to get from a newsgroup like comp.lang.objective-c. Which is what i got !!
Pierre
|
|
 | | From: | Sherm Pendley | | Subject: | Re: Cocoa GC ? | | Date: | Fri, 10 Dec 2004 01:12:46 -0500 |
|
|
 | Pierre Chatel wrote:
> On 2004-12-09 17:18:09 -0500, Sherm Pendley said: > >> Take a step back - what problem did you encounter, that you thought >> that garbage collection would provide an answer to? > > none. In fact, if you had read the thread from the beginning
No need to get defensive, I didn't mean that as criticism.
I *did* read the whole thread, and your other "autorelease" thread as well. Between the two threads, it looks to me like you're looking for a "simpler" alternative because of the problems you're having with autorelease.
But automatic GC has its own problems, especially when you're trying to use it with a language and framework that wasn't built around it, and for which you don't have the source code.
I stand by my statement - Whatever difficulties you might be having with Cocoa's autorelease, trying to force Cocoa into an automatic GC mold is probably not the best answer to them.
sherm--
-- Cocoa programming in Perl: http://camelbones.sourceforge.net Hire me! My resume: http://www.dot-app.org
|
|
 | | From: | Michael Ash | | Subject: | Re: Cocoa GC ? | | Date: | Thu, 09 Dec 2004 13:06:59 -0600 |
|
|
 | Pierre Chatel wrote: > On 2004-12-09 02:11:57 -0500, Michael Ash said: > >> Pierre Chatel wrote: >>> Is there a garbage collector implementation for Cocoa (i heard that it >>> was impossible due to refcounting memory management in cocoa). What >>> about Boehm ? >> >> ObjC has the same limitations as C does as far as garbage collectors >> go, but boehm is there and it works. GNUStep has the option of using >> boehm, so it's obviously possible. >> >> Cocoa has some architectural limitations that would need to be >> addressed before it could use boehm. For example, a great deal of code >> signs up for notifications with NSNotificationCenter, and removes >> itself from the notification in the -dealloc method. While this works >> fine with manual reference counting, since NSNotificationCenter doesn't >> retain its clients, a garbage collector would see that the object still >> has a live reference and would not collect it, turning it into a >> chicken-and-egg situation. NSNotificationCenter and any other object >> that relies on -dealloc to clear a reference would have to be modified >> to use weak references, which would be particularly hard to do given >> that Cocoa is not open source. > > i see... i'm wondering how java's dealing with this notification model. > Objects that registered themselves to a notifier (which is storing refs > on arrays or such) would never be garbage collected, right ? Except if > they dont explicitely de-register themselves. As far as i know u don't > have access to a -dealloc equivalent in Java. So could u just add > "categories" to cocoa classes with correct weak references in order for > boehm to work... Maybe overiding doesn't work well in with categories
I don't believe Java has the same kind of notification mechanism as Cocoa does. However, there is a standard way of dealing with this situation, which is weak references. (These are references that don't "count" when it comes to deciding whether an object is live.) You could certainly go through Cocoa and modify it to use weak references for all of the things that needed it, and you could even do it without needing the code, but it would be hard to *find* all of the places that needed it without having the code. It might also involve rewriting large chunks of code.
|
|
 | | From: | David Stes | | Subject: | Re: Cocoa GC ? | | Date: | Thu, 09 Dec 2004 21:26:25 GMT |
|
|
 | Michael Ash wrote: > > I don't believe Java has the same kind of notification mechanism as Cocoa > does.
The former is a language, while the latter is a library ...
It is possible to implement a library in Java that keeps references to all objects.
You can for instance write a Cocoa style memory management on top of Java, in order to make it impossible for Java to do GC.
|
|
 | | From: | Michael Ash | | Subject: | Re: Cocoa GC ? | | Date: | Thu, 09 Dec 2004 15:47:24 -0600 |
|
|
 | David Stes wrote: > Michael Ash wrote: >> >> I don't believe Java has the same kind of notification mechanism as Cocoa >> does. > > The former is a language, while the latter is a library ...
"Java" refers to a language, a large class library, a virtual machine, and probably some other things I've forgotten about.
|
|