Re: Weak callbacks?

2013-11-07 Thread Terrence Cole
On 11/06/2013 07:37 PM, K. Gadd wrote: Generally speaking, all the discussions on this list about WRs so far have not suggested that there is any way to introduce WeakRefs without making GC behavior observable in some fashion. WeakRefs functionally make GC observable because when you try to

Re: Weak callbacks?

2013-11-07 Thread K. Gadd
When I talk about the importance of weak references I am *not* talking about the importance of finalization for managing native/remote resources; that's an important consideration but it's a separate one. When I talk about why weak references are important, I mean for the purposes of building

Re: Weak callbacks?

2013-11-07 Thread Mark S. Miller
Could you give an example, hopefully simple, of such a problem you can solve better with GC + weakmaps + weakrefs but without finalization, vs just GC + weakmaps ? Thanks. On Thu, Nov 7, 2013 at 1:46 PM, K. Gadd k...@luminance.org wrote: When I talk about the importance of weak references I am

Re: Weak callbacks?

2013-11-07 Thread K. Gadd
I'll try and restate an example I used before. Let's say you're building a somewhat simple tab-based application, where each tab represents a different 'mode'. In this case, you need a higher level coordinating object that manages the tab bar, and it needs to own references to all of the active

Re: Weak callbacks?

2013-11-07 Thread felix lee
That example looks to me like it could be implemented with WeakMap instead of WeakRef. Am I missing something? On Thu Nov 07 2013 at 2:43:45 PM, K. Gadd k...@luminance.org wrote: I'll try and restate an example I used before. Let's say you're building a somewhat simple tab-based application,

Re: Weak callbacks?

2013-11-07 Thread K. Gadd
I am not aware of any way to implement my described scenario using WeakMaps without having the same cycle collection issues. I haven't seen any examples of WeakMap used for this in the wild either. On Thu, Nov 7, 2013 at 2:48 PM, felix lee feli...@gmail.com wrote: That example looks to me like

Re: Weak callbacks?

2013-11-07 Thread felix lee
Ah, sorry, I misread your description of the relationships. Yeah, that would be hard to do with WeakMaps. On Thu Nov 07 2013 at 3:02:02 PM, K. Gadd k...@luminance.org wrote: I am not aware of any way to implement my described scenario using WeakMaps without having the same cycle collection

Re: Weak callbacks?

2013-11-07 Thread David Bruant
Le 07/11/2013 22:46, K. Gadd a écrit : That's the sort of obstacle that factors into a developer's choice of language and toolset. I've seen this particular concern with ES crop up in the past on real projects, and I've seen firsthand how difficult it is to avoid uncollectable cycles in a

Re: Weak callbacks?

2013-11-07 Thread K. Gadd
The problem is that the cycles remain uncollectable for a very long period of time, even though functionally the references don't need to be strong. On Thu, Nov 7, 2013 at 3:10 PM, David Bruant bruan...@gmail.com wrote: Le 07/11/2013 22:46, K. Gadd a écrit : That's the sort of obstacle that

Re: Weak callbacks?

2013-11-07 Thread Mark Miller
I agree. This is a good use for weakrefs without the need for finalization. Thanks! On Thu, Nov 7, 2013 at 3:12 PM, K. Gadd k...@luminance.org wrote: The problem is that the cycles remain uncollectable for a very long period of time, even though functionally the references don't need to be

Re: Weak callbacks?

2013-11-07 Thread Domenic Denicola
Would someone be interested in putting together a small code example, before and after weak refs, illustrating this situation? I have a feeling this conversation will be referenced in many future threads, and the added clarity of code would be greatly helpful. On 7 Nov 2013, at 18:16, Mark

Re: Weak callbacks?

2013-11-07 Thread Marius Gundersen
On Thu, Nov 7, 2013 at 11:42 PM, K. Gadd k...@luminance.org wrote: I'll try and restate an example I used before. Let's say you're building a somewhat simple tab-based application, where each tab represents a different 'mode'. In this case, you need a higher level coordinating object that

Re: Weak callbacks?

2013-11-07 Thread K. Gadd
Please reread my example, events are a part of it but it is not exclusively about events. My example explicitly demonstrates the modes holding references in *both* directions, and only one of them is an event listener. You're correct that weak event listeners solve some of the problems that are

Re: Weak callbacks?

2013-11-07 Thread Mark Miller
On Thu, Nov 7, 2013 at 4:27 PM, Marius Gundersen gunder...@gmail.comwrote: It seems that every (real) usecase for weakRefs, weakMaps and weakSets is to implement a weak event listener system. Not true. Even silly. Unfortunately weak event listeners cannot be implemented with the current

Re: Weak callbacks?

2013-11-07 Thread Marius Gundersen
On Nov 8, 2013 1:46 AM, Mark Miller erig...@gmail.com wrote: On Thu, Nov 7, 2013 at 4:27 PM, Marius Gundersen gunder...@gmail.com wrote: It seems that every (real) usecase for weakRefs, weakMaps and weakSets is to implement a weak event listener system. Not true. Even silly. Sorry, I may