Summary
Overwriting an array slot that holds the last strong reference does not clear
weakened references in PerlOnJava. This affects both the JVM and interpreter
backends and breaks Perl's observable weak-reference lifetime semantics.
Minimal reproducer
use strict;
use warnings;
use Scalar::Util qw(weaken);
my $object = bless {}, 'Thing';
my $weak = $object;
weaken($weak);
my @array = ($object);
undef $object;
$array[0] = undef;
print defined($weak) ? "retained\n" : "released\n";
Standard Perl prints released. Both PerlOnJava backends print retained.
The same problem occurs when the array is nested in a hash and when the array
reference is first copied into a local variable.
CPAN evidence
Algorithm::SlidingWindow 1.002 failed in CPAN tester run
20260827-171022-1876. Its pure-Perl reference-lifetime test passes under
standard Perl but fails under PerlOnJava:
t/refs.t: obj1 freed after eviction (slot cleared) fails on the JVM
backend.
t/refs.t: obj2 freed after clear (slots cleared) fails on both backends.
The distribution stores values in a circular array buffer, explicitly replaces
evicted/cleared slots with undef, and expects that to promptly release the
last strong reference.
Expected behavior
When the final strong reference to a referent is removed through an array-slot
overwrite, any weak references to that referent must immediately become
undefined. This must be true for direct arrays, arrays reached through a hash,
and aliases to an array reference.
Suggested acceptance coverage
- Add project-owned regression tests for direct and nested array-slot
replacement with undef after Scalar::Util::weaken.
- Cover circular-buffer eviction and clearing, matching the stable
Algorithm::SlidingWindow scenarios.
- Run those tests on both JVM and interpreter backends.
- Ensure the release path continues to dispatch
DESTROY correctly where the
referent defines one.
Summary
Overwriting an array slot that holds the last strong reference does not clear
weakened references in PerlOnJava. This affects both the JVM and interpreter
backends and breaks Perl's observable weak-reference lifetime semantics.
Minimal reproducer
Standard Perl prints
released. Both PerlOnJava backends printretained.The same problem occurs when the array is nested in a hash and when the array
reference is first copied into a local variable.
CPAN evidence
Algorithm::SlidingWindow1.002 failed in CPAN tester run20260827-171022-1876. Its pure-Perl reference-lifetime test passes understandard Perl but fails under PerlOnJava:
t/refs.t:obj1 freed after eviction (slot cleared)fails on the JVMbackend.
t/refs.t:obj2 freed after clear (slots cleared)fails on both backends.The distribution stores values in a circular array buffer, explicitly replaces
evicted/cleared slots with
undef, and expects that to promptly release thelast strong reference.
Expected behavior
When the final strong reference to a referent is removed through an array-slot
overwrite, any weak references to that referent must immediately become
undefined. This must be true for direct arrays, arrays reached through a hash,
and aliases to an array reference.
Suggested acceptance coverage
replacement with
undefafterScalar::Util::weaken.Algorithm::SlidingWindowscenarios.DESTROYcorrectly where thereferent defines one.