Skip to content

Don't cache JRuby runtime in static fields #707

Description

@headius

There are a few places where we cache the JRuby runtime or runtime-specific objects in a static field, such as here with a WeakReference:

public static RuntimeInfo forRuntime(Ruby runtime) {
synchronized (RuntimeInfo.class) {
if (runtime1.get() == runtime) return info1;
RuntimeInfo cache = null;
if (runtimes != null) cache = runtimes.get(runtime);
assert cache != null : "Runtime given has not initialized JSON::Ext";
return cache;
}
}

The runtimes cached in weak references will not "leak" but it may take longer for the runtime to be collected than normal. In addition, the cost of traversing the weak reference may offset any gains from caching runtime objects.

These should be removed and cached in a runtime-safe way.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions