Opened 4 years ago

Closed 4 years ago

Last modified 4 years ago

#10780 closed bug (wontfix)

Weak reference is still alive if key is alive, but weak reference itself not reachable

Reported by: atze Owned by: simonmar
Priority: normal Milestone:
Component: Runtime System Version: 7.10.2
Keywords: Cc:
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: Runtime performance bug Test Case:
Blocked By: Blocking:
Related Tickets: Differential Rev(s):
Wiki Page:


We've been running into some unexpected behavior with weak references. The use case it hackage package HMap, which is a (heterogenous, but that is besides the point) map from keys to values. Since there is no way to enumerate all elements in the map, there is no way to obtain a value for a key if the key is dead.

As an optimization, I therefore used weak references to the values in the map, such that if the key dies, then the value is also dead. I was under the impression that a weak reference is alive if: (1): The key is still alive AND (2): The weak reference itself is alive (i.e. reachable from root set)

However, the actual behavior is that a weak reference is alive if (1), (2) does not matter. Hence, the weak references here actually create a space leak, because an alive key will keep all values in all maps that it was ever used in alive.

I think it would be desirable, to change the behavior to (1) AND (2), instead of just (1). This would prevent space leaks in this use case instead of creating them. Or would this cause problems in other use cases?

See also:

Change History (2)

comment:1 Changed 4 years ago by simonmar

Resolution: wontfix
Status: newclosed

This is working as intended, see

The paper includes an implementation of a memo table, which should help with the situation in HMap.

comment:2 Changed 4 years ago by atze

Thanks! The paper indeed discusses and gives a nice solution to this. Subtle stuff :)

Note: See TracTickets for help on using tickets.