SiyaoIsHiding commented on code in PR #1743:
URL:
https://github.com/apache/cassandra-java-driver/pull/1743#discussion_r1640458423
##########
core/src/main/java/com/datastax/oss/driver/internal/core/metadata/NodeStateEvent.java:
##########
@@ -53,14 +55,19 @@ public static NodeStateEvent removed(DefaultNode node) {
*/
public final NodeState newState;
- public final DefaultNode node;
+ private final WeakReference<DefaultNode> node;
Review Comment:
@absurdfarce I will try to revert the changes and see whether it still
leaks, but:
There are two `WeakHashMap` held by `ControlConnection`:
```java
private final Map<Node, DistanceEvent> lastDistanceEvents = new
WeakHashMap<>();
private final Map<Node, NodeStateEvent> lastStateEvents = new
WeakHashMap<>();
```
However, both DistanceEvent and NodeStateEvent hold strong references to the
associated node
From the
[doc](https://docs.oracle.com/javase/8/docs/api/java/util/WeakHashMap.html) of
WeakHashMap:
> Implementation note: The value objects in a WeakHashMap are held by
ordinary strong references. Thus care should be taken to ensure that value
objects do not strongly refer to their own keys, either directly or indirectly,
since that will prevent the keys from being discarded.
In this case `DistanceEvent` and `NodeStateEvent` are the values that hold
strong references to the keys. Therefore, I think it may leak references.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]