File tree Expand file tree Collapse file tree 3 files changed +16
-8
lines changed Expand file tree Collapse file tree 3 files changed +16
-8
lines changed Original file line number Diff line number Diff line change @@ -320,16 +320,20 @@ protected boolean isStackEmpty() {
320
320
return _stack .size () < 1 ;
321
321
}
322
322
323
- private static HashMap <String , Object > _getRuntimeCache (Ruby runtime ) {
324
- // each JRuby runtime may have different objects for these constants,
325
- // so cache them separately for each runtime
323
+ private static HashMap <String , Object > _getRuntimeCache (final Ruby runtime ) {
326
324
@ SuppressWarnings ("unchecked" )
327
325
HashMap <String , Object > cache = _runtimeCache .get ( runtime );
328
326
329
327
if (cache == null ) {
330
328
cache = new HashMap <String , Object >();
331
329
_runtimeCache .put ( runtime , cache );
330
+ runtime .addFinalizer ( new Finalizable () {
331
+ public void finalize () {
332
+ _runtimeCache .remove (runtime );
333
+ }
334
+ });
332
335
}
336
+
333
337
return cache ;
334
338
}
335
339
Original file line number Diff line number Diff line change @@ -763,15 +763,19 @@ public void writeCString( String s ){
763
763
private ByteBuffer _stringB = ByteBuffer .wrap ( new byte [1024 + 1 ] );
764
764
private CharsetEncoder _encoder = Charset .forName ( "UTF-8" ).newEncoder ();
765
765
766
- private static Map _getRuntimeCache (Ruby runtime ) {
767
- // each JRuby runtime may have different objects for these constants,
768
- // so cache them separately for each runtime
769
- Map cache = (Map ) _runtimeCache .get ( runtime );
766
+ private static Map _getRuntimeCache (final Ruby runtime ) {
767
+ Map cache = (Map ) _runtimeCache .get (runtime );
770
768
771
769
if (cache == null ) {
772
770
cache = new HashMap ();
773
- _runtimeCache .put ( runtime , cache );
771
+ _runtimeCache .put (runtime , cache );
772
+ runtime .addFinalizer ( new Finalizable () {
773
+ public void finalize () {
774
+ _runtimeCache .remove ( runtime );
775
+ }
776
+ });
774
777
}
778
+
775
779
return cache ;
776
780
}
777
781
You can’t perform that action at this time.
0 commit comments