Annotation Type PreventsGarbageCollection


  • @Retention(SOURCE)
    @Target(FIELD)
    @Internal
    public @interface PreventsGarbageCollection
    Indicates that at least one purpose of the annotated field is to prevent the value from being garbage collected.

    This annotation is strictly advisory, and has no effect at runtime.

    Why do we hold references just to prevent garbage collection? One reason is because we want to automatically disconnect an AsyncCluster when it becomes unreachable, so the Core doesn't live on as a socket-slurping zombie. However, we don't want to disconnect the cluster until any Buckets, Scopes, Collections, and Managers associated with the cluster also become unreachable. To that end, each of those "satellite" objects holds a reference back to the cluster, just to prevent the cluster from becoming unreachable until all the satellites are also unreachable.

    We explored attaching the "auto-disconnect" behavior to the Core instead of the cluster, but unfortunately the Core never becomes eligible for garbage collection, presumably because it's referenced by one or more schedulers.